www.webdeveloper.com
Results 1 to 3 of 3

Thread: preg_replace Regex Help!!

  1. #1
    Join Date
    Apr 2003
    Posts
    31

    preg_replace Regex Help!!

    Code:
    $info[0] = "/apple/farm/";
    $the_path = "/apple/";
    $cat_rep = preg_replace("/^$the_path/", "", $info[0]);
    
    echo $cat_rep;

    Im trting to get $cat_rep to contain "farm/", instead I get this error:
    Warning: Unknown modifier 'a' in

    Please help. I see how its doing somethign with / and trying to end the regex with apple as a modifier. What should I do?

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Seeing how a slash ( / ) is a regexp special character, you must use a backslash ( \ ) to escape them.

    PHP Code:
    <?PHP
    $info
    [0] = "/apple/farm/";
    $the_path "\\/apple\\/";
    $cat_rep preg_replace("/^$the_path/"""$info[0]);

    echo 
    $cat_rep;
    ?>

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  3. #3
    Join Date
    Apr 2003
    Posts
    31
    Thanks got it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles