Click to See Complete Forum and Search --> : preg_replace Regex Help!!


iceafreak99
06-18-2003, 04:58 PM
$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?

pyro
06-18-2003, 05:14 PM
Seeing how a slash ( / ) is a regexp special character, you must use a backslash ( \ ) to escape them.

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

echo $cat_rep;
?>

iceafreak99
06-19-2003, 09:17 AM
Thanks got it.