1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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?
    SEMrush
    thanks in advance.
     
    Kyriakos, Apr 19, 2013 IP
    SEMrush
  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