Possible Duplicate:
Unknown modifier in regular expression
Hey guys I’m getting an Unknown Modifier warning (fail) when trying to
replace the fourth slash in a sequence with a hashmark using preg_replace,
hoping you can help.
$value['path'] = preg_replace("/((.*?)(/)){4}/e", '(preg_replace("//$/", "", "\0"))#', $value['path']);
Error:
Warning: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier ')'
If you use
/as a delimiter, you need to escape all/in the middle of the regex.Personally I like to use
()as delimiters, because it doesn’t require any escaping and it reminds me that the first match (index 0) is the entire pattern.Side-note: Do NOT use the
emodifier. Usepreg_match_callbackinstead.Also, you can replace the 4th instance of a slash by doing something like this: