I'm trying to $var = str_replace('\','/',$var); and writes a mistake

  • 9
    $var = str_replace('\\','/',$var); - PinkTux
  • 3
    rtfm: php.net/manual/ru/… - uorypm
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

You need to use double backslash:

 $str = str_replace('\\', '/', $str); 

Source: enSO .

  • one
    It would be nice to explain why double slash. Why single gives an error. - cache
  • one
    So the source is enSO, not the manual. It is clear - uorypm

the \ sign means shielding of characters - therefore it gives an error, in this case \ it will show that the second slash should be regarded as a normal character.