Unknown modifier '/' in ...? what is it? [duplicate]
I assume $value
contains a slash /
, which is not escaped by preg_quote
:
The special regular expression characters are:
. \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
Pass the delimiter you use to the function:
preg_match_all("/[^\s]*".preg_quote($value, '/')."[^\s]*/iu", $row_search['content'], $final_matched);
// ---^
or use another delimiter.
You should change your preg_quote($value)
into preg_quote($value, "/")
to escape the delimiter too.
In your example if $value
contains "(content/other)" it will be escaped as "(content/other)" and this in your regex will be /[^\s]*\(content/other\)[^\s]*/iu
as you can see there is a / which will case your regex to crash. If you explicitly say that "/" is the delimiter then the regex will be /[^\s]*\(content\/other\)[^\s]*/iu
/
is not a PCRE metacharacter, so although you're using it as the delimiter in your regular expression, preg_quote()
won't escape it because it doesn't know you're using it as the delimiter. You'll have to pass it in as the second parameter, as the rest have said, in order for it to be escaped too:
preg_match_all("/[^\s]*".preg_quote($value, '/')."[^\s]*/iu", $row_search['content'], $final_matched);