【发布时间】:2014-05-23 08:31:19
【问题描述】:
我正在使用preg_match_all() 来从 HTML 文件中提取所有密钥字符串。
每个键字符串都在 _@#$%&KEY_NAME&%$#@_ 之类的模式中。
所以我有:
$html = file_get_contents("htmlFile.html");
if ($html){
$matches = null;
$keys = preg_match_all("/(_@#\$%&)(?P<key>\w+)(&%\$#@_)/", $html, $matches, PREG_SET_ORDER);
if (($keys >= 0)&&($keys != false)){
if ($keys == 0)
echo "preg_match_all() returns 0";
else{
foreach($matches as $val)
echo $val[key];
}
}
}
HTML 文件内容:
<label for="button_ok">_@#$%&LABEL_BUTTON_OK&%$#@_</label>
<input type="button" value="_@#$%&TEXT_BUTTON_OK&%$#@_" />
在http://tryphpregex.com/ 对其进行测试时,它说没有找到模式。
【问题讨论】: