preg_replace (this should be easy??)

Discussion in 'PHP' started by RickF, Jul 25, 2008.

  1. #1
    Hi Folks,

    I've spent way to long on this and probably cuz I've not slept well the past few nights. But I'm stuck.

    I've looked at the preg_replace php manual, and now I'm even more confused.

    Here is what I want it to do:

    I want to take "./uploads/wecanhelp" whic is the contents of $folder
    and make it into just "/wecanhelp"

    I've tried a number of things but I'm back to my original thought. I've looked through the forum and I'm sure in here some where is my answer but here I am asking for help in here.
    this is what I'm back to:

    $data = "./uploads/wecanhelp";// contents of $folder
    echo "$data <br>";// just echo out something
    $find ="./uploads/"; //this is what I'm looking for
    $replace ="/"; //this is what I want to replace it with.
    echo preg_replace ($find, $replace, $data); //this should give me my result

    Any help much appreciated.

    Regards
    Rick
     
    RickF, Jul 25, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    preg_replace is just for regular expressions (which are not needed in this case).

    Leave your current code as it is, just use str_replace() instead of preg_replace().


    www.php.net/str_replace
     
    nico_swd, Jul 25, 2008 IP
  3. tyr897

    tyr897 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You could just use basename and add a slash.

    echo '/'.basename($data);

    http://us3.php.net/basename
     
    tyr897, Jul 25, 2008 IP
  4. RickF

    RickF Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Thanks to both of you, they both work,

    I hoped this was going to be easy, my eyes are blood shot and there you have it,, I owe you both a beer.

    Thanks

    Rick
     
    RickF, Jul 25, 2008 IP