2014-03-19 240 views
-1
$ohtml = '<!--#comp: {}-->I am HTML and whatever else<!--##comp-->'; 
preg_match_all('/\Q<!--#comp\E(.*?)\Q<!--##comp-->\E/', $othml, $match); 
print_r($match); 

完美的作品上http://regex101.com/但是在PHP它提出了500服务器错误PHP正则表达式工作regex101但不是在PHP

+1

请注意,您在这里没有任何可以逃脱的地方,您应该删除所有无用的'\ Q ... \ E'。 –

回答

0

你的字符串是$ohtml但在正则表达式使用$othml。这是罪魁祸首!

$ohtml = '<!--#comp: {}-->I am HTML and whatever else<!--##comp-->'; 
    ^^ check here 

preg_match_all('/\Q<!--#comp\E(.*?)\Q<!--##comp-->\E/', $othml, $match); 
                  ^^ and here 
+0

谢谢。我必须工作太多...... –

相关问题