我不知道如何修复此错误
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)) {
我想将eregi的php版本更新为preg_match,我就是这个
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 ( preg_match($patt,$v,$res)) {
答案 0 :(得分:1)
正如您在此回答中所看到的,preg_match将第一个字符视为分隔符 How to change PHP's eregi to preg_match
具体而言,您会收到错误,因为preg_match使用'('作为分隔符,因此在($ this-> block_start_word | $ this-> block_end_word)之后结束模式并且'['
上的错误将图案更改为 $ PATT =“/($这 - &GT; block_start_word | $这 - &GT; block_end_word)[[:空白:]] ([0-9A-ZA-Z _] +)[[:空白:]] < / EM> $这 - &GT;(。*)block_end_delim /“;
它应该有效,Goodluck!
答案 1 :(得分:0)
好的,我们来看看这个正则表达式:
"($this->block_start_word|$this->block_end_word)[[:blank:]]*([0-9a-zA-Z\_]+)[[:blank:]]*$this->block_end_delim(.*)"
我认为你想要:
$this->block_start_word
或$this->block_end_word
$this->block_end_delim
那个,怎么样
<?php
$handle = fopen('php://stdin', "r");
while (($line = fgets($handle, 4096)) !== false) {
$exp = '/';
$exp .= '(';
$exp .= '\$this\-\>block_start_word';
$exp .= '|';
$exp .= '\$this\-\>block_end_word';
$exp .= ')';
$exp .= '\s*'; // Like [[:blank:]]*
$exp .= '([0-9a-zA-Z\_]+)';
$exp .= '\s*'; // Like [[:blank:]]*
$exp .= '\$this\-\>block_end_delim';
$exp .= '(.*)/';
if(preg_match($exp,$line)) {
print $line;
}
}
?>
如果{1}},$this->block_start_word
和$this->block_end_word
设置在PHP脚本的其他位置:
$this->block_end_delim
答案 2 :(得分:0)
使用preg_match
您应该定义分隔符,并且最好还包括preg_quote
:
$patt="/(".preg_quote($this->block_start_word)."|".preg_quote($this->block_end_word."))[[:blank:]]*([0-9a-zA-Z\_]+)[[:blank:]]*".preg_quote($this->block_end_delim)."(.*)/";