Unknown modifier '/' in ...? what is it? [duplicate]
Asked Answered
B

4

0

When i wrote the following, i get such warning, and it doesn't match anything, but i'm sure, that $row_search['content'] contains $value...

preg_match_all("/[^\s]*".preg_quote($value)."[^\s]*/iu", $row_search['content'], $final_matched);

WARNING:preg_match_all() [function.preg-match-all]: Unknown modifier '/' in C:\xampp\htdocs\finance\search\search.php on line 82

why i get such warning message?

Thanks

Bagpipes answered 25/8, 2010 at 12:8 Comment(1)
what is the content of $value ?Swagger
S
6

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.

Swagger answered 25/8, 2010 at 12:12 Comment(0)
G
4

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

Glomeration answered 25/8, 2010 at 12:12 Comment(0)
S
2

/ 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);
Semite answered 25/8, 2010 at 12:16 Comment(0)
D
0

Specify / as delimiter when using preg_quote:

preg_match_all("~/[^\s]*~".preg_quote($value, '/')."[^\s]*/iu", $row_search['content'], $final_matched);

Otherwise a / in the value of $value will not get escaped.

Decumbent answered 25/8, 2010 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.