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

那年仲夏 提交于 2019-12-23 10:06:24

问题


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?


回答1:


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]+)$/', .....) {


来源:https://stackoverflow.com/questions/5321068/warning-preg-match-function-preg-match-unknown-modifier-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!