Warning: preg_match() [function.preg-match]: Unknown modifier 'v'
Asked Answered
G

1

5

I keep getting this error about 20 times in my wordpress blog about the same line of code. Here is the line of code that keeps getting the error.

if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) )
        $number = max($number, $matches[1]);

What could be wrong?

Goner answered 16/3, 2011 at 4:32 Comment(0)
M
5

Your regex will break if the string $id_base has a / in it as you are using / as the regex delimiter.

To fix this use preg_quote on $id_base as:

if (preg_match('/'. preg_quote($id_base,'/').'-([0-9]+)$/', .....) {
Maintain answered 16/3, 2011 at 4:36 Comment(3)
so use 'preg_quote' instead of '$id_base'? how would you rewrite the line?Goner
@Frank: My answer has the usage.Maintain
whoops, sorry didnt see it. LOLGoner

© 2022 - 2024 — McMap. All rights reserved.