Problem with "\" (backslash) character

Discussion in 'PHP' started by Kyriakos, Apr 19, 2013.

  1. #1
    hi.

    i want to use str_replace in my page with the following code
    echo = str_replace("Z:\", "/images/", $row['sofname']);
    PHP:
    witch Z:\ is the local path of image folder (network drive) and i want to replace it with "/images/". But in PHP the \ it's used for another purpose and it's not working.
    How i can use this character inside the str_replace?

    thanks in advance.
     
    Kyriakos, Apr 19, 2013 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    You need to escape the backslash by adding another backslash in front of it.

    
     
    <?php
    $string = "Z:\\path\sub";
    $replaced = str_replace('Z:\\', '/images/', $string);
    var_dump($replaced);
    ?>
     
    
    PHP:
    Tested code, works.
     
    HuggyStudios, Apr 19, 2013 IP