Hello.

Recently it was necessary to find in the line slashes. I decided to use this code:

$ret = substr_count($uploadfilename,'\\'); 

$ uploadfilename contains the character code of the type "\ u0414 \ u4414".

The code does not work gives 0, strangely somehow, although it seems that the error is not at the level of a comma.

  • need to find their number or even the presence? - Barton
  • Copied code, checked - result: 2 - Barton
  • Amount. Why then may not work? - easy
  • Maybe slashes in different directions? - Nikolai Kim
  • 6
    For some reason it seems to me that you have a unicode string and you look at its abstract representation in the form of \uxxxx and think that this is exactly the text in which you must read the slashes, but in fact you don’t have \ u0414 \ u4414 in the string and D [hieroglyph] - ReinRaus

2 answers 2

"\u0414\u4414"

There are no slashes in this line, these are Unicode characters indicated by the coding sequence \uxxxx

"\\u0414\\u4414"

And in this there, here are slashes screened

 echo $ret = substr_count("\\u0414\\u4414",'\\'); // 2 

If you see the original string in JSON, decode it via json_decode:

 echo $s = json_encode('Привет'); // "\u041f\u0440\u0438\u0432\u0435\u0442" echo "\n"; echo json_decode($s); // Привет 
     preg_match_all('/#[^\s]+/', $input, $output); 

    only here I choose all the words with