Results 1 to 2 of 2

Thread: repace '/' to '\'?

  1. #1
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default repace '/' to '\'?

    hi all
    My filepath looks like w:/aaa/bbb/ccc/abc.doc.
    I want to replace all '/' to '\'.
    my code don't work and occurs error

    for($i=0; $i<count($VFILE); $i++){
    $tmp= $VFILE[$i];
    $tmpstr='';
    for($j=0; $j<strlen($tmp); $j++){
    if($tmp[$j]== '/'){$tmp[$j]= "\";}
    $tmpstr=$tmpstr . $tmp[$j];
    }
    $VFILE[$i]= $tmpstr;
    }

    if I change the red section code to if($tmp[$j]== '/'){$tmp[$j]= "\\";}
    It works, but I got two '\\'?
    Are there some codes to fit my program?

  2. #2
    Join Date
    Dec 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <?
    $url = "/aaa/bbb/ccc/abc.doc";
    
    $newurl = str_replace("/", "\\", $url);
    
    echo $newurl;
    ?>
    basically, if u use an "\" then it will escape the next character, so using "\\" will excape the second "\" so it will be readable by the php engine as "\" not
    "\\" anymore

    about the $url, maybe u can use $_SERVER["DOCUMENT_ROOT"]; or just declare it by yourself.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •