Replacing backslashes with forward slashes with str_replace() in php

前端 未结 6 1699
花落未央
花落未央 2020-12-09 14:29

I have the following url:

$str = \"http://www.domain.com/data/images\\flags/en.gif\";

I\'m using str_replace to try and replac

相关标签:
6条回答
  • 2020-12-09 15:04

    You need to escape backslash with a \

      $str = str_replace ("\\", "/", $str);
    
    0 讨论(0)
  • 2020-12-09 15:06

    You want to replace the Backslash?

    Try stripcslashes:

    http://www.php.net/manual/en/function.stripcslashes.php

    0 讨论(0)
  • 2020-12-09 15:07

    No regex, so no need for //.

    this should work:

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

    You need to escape "\" as well.

    0 讨论(0)
  • 2020-12-09 15:09

    Single quoted php string variable works.

    $str = 'http://www.domain.com/data/images\flags/en.gif';
    $str = str_replace('\\', '/', $str);
    
    0 讨论(0)
  • 2020-12-09 15:15

    you have to place double-backslash

    $str = str_replace('\\', '/', $str);
    
    0 讨论(0)
  • 2020-12-09 15:24
    $str = str_replace('\\', '/', $str);
    
    0 讨论(0)
提交回复
热议问题