将PHP的eregi转换为preg_match

时间:2015-01-15 21:49:42

标签: php wamp eregi

我不知道如何修复此错误

 Warning: preg_match(): Unknown modifier '[' in 

我的代码是

while(list($k,$v)=each($con2)) {
    $patt="($this->block_start_word|$this->block_end_word)[[:blank:]]*([0-9a-zA-Z\_]+)[[:blank:]]*$this->block_end_delim(.*)";
    if (eregi($patt,$v,$res)) {

我想将php版本的eregi更新为preg_match,我试试这个

hile(list($k,$v)=each($con2)) {
    $patt="($this->block_start_word|$this->block_end_word)[[:blank:]]*([0-9a-zA-Z\_]+)[[:blank:]]*$this->block_end_delim(.*)";
    if ( preg_match($patt,$v,$res)) {

1 个答案:

答案 0 :(得分:0)

你忘记了正则表达式的分隔符,所以只需改变它:

if ( preg_match($patt,$v,$res)) {

为:

if ( preg_match("/" . $patt . "/",$v,$res)) {