Php 从HTML中提取值
可能重复:Php 从HTML中提取值,php,regex,preg-match-all,Php,Regex,Preg Match All,可能重复: 我试图从一些html中提取值。下面是我试图从中获取值的HTML文档的一部分 <input type="hidden" id="first" value='€218.33' /> <input type="hidden" id="second" value='€291.08' /> <input type="hidden" id="third" v
我试图从一些html中提取值。下面是我试图从中获取值的HTML文档的一部分
<input type="hidden" id="first"
value='€218.33' />
<input type="hidden" id="second"
value='€291.08' />
<input type="hidden" id="third"
value='€344.77' />
我使用了下面的preg match all命令,其中$buffer包含我正在搜索的页面的整个html
if (preg_match_all('/<input type="hidden" id="(.+?)" value=\'€(.+?)\'/', $buffer, $matches))
{
echo "FOUND";
echo $matches[2][0] . " " . $matches[2][1] . " " . $matches[2][2] . "\n";
}
if(preg_match_all)('/一个非常简单的解决方案是使用PHP简单HTML DOM解析器
HTML示例
include "simple_html_dom.php" ;
$html =" <input type=\"hidden\" id=\"first\"
value='€218.33' />
<input type=\"hidden\" id=\"second\"
value='€291.08' />
<input type=\"hidden\" id=\"third\"
value='€344.77' />";
输出
€218.33
€291.08
€344.77
一个非常简单的解决方案是使用PHP简单HTML DOM解析器
HTML示例
include "simple_html_dom.php" ;
$html =" <input type=\"hidden\" id=\"first\"
value='€218.33' />
<input type=\"hidden\" id=\"second\"
value='€291.08' />
<input type=\"hidden\" id=\"third\"
value='€344.77' />";
输出
€218.33
€291.08
€344.77
那怎么办
if (preg_match_all('/<input type="hidden" id="(.+?)".+?value=\'€(.+?)\'/s', $buffer, $matches))
if(preg_匹配所有('/
if (preg_match_all('/<input type="hidden" id="(.+?)".+?value=\'€(.+?)\'/s', $buffer, $matches))
if(preg_match_all('/此regexp不返回任何内容,因为id和值之间有多个空格
preg_match_all('/<input type="hidden" id="(.+?)"[.\s\t\r\n\v\f]*?value=\'€(.+?)\'/', $buffer, $matches)
preg\u match\u all('/此regexp不返回任何内容,因为id和值之间有多个空格
preg_match_all('/<input type="hidden" id="(.+?)"[.\s\t\r\n\v\f]*?value=\'€(.+?)\'/', $buffer, $matches)
preg\u match\u all(“/是一个非常易于使用的PHP HTML paraser。@Adnan SimpleHTMLDom是crapware IMO。建议的第三方替代方案实际用于代替字符串解析:,。是一个非常易于使用的PHP HTML paraser。@Adnan SimpleHTMLDom是crapware IMO。建议的第三方替代方案实际用于代替字符串解析:,and.@Gordon单击str_get_html它将带您到PHP简单html DOM解析器:@Gordon单击str_get_html它将带您到PHP简单html DOM解析器:不同的平台不会将。视为换行符。指定换行符也更安全。s(PCRE\u DOTALL)如果设置了此修饰符,则模式中的点元字符将匹配所有字符,包括换行符。如果不设置此修饰符,则会排除换行符。此修饰符相当于Perl的/s修饰符。例如[^a]的负类始终与换行符匹配,与此修饰符的设置无关。
说明手册。不同的平台不将。视为换行符。指定换行符也更安全。s(PCRE\u DOTALL)如果设置了此修饰符,则模式中的点元字符将与所有字符(包括换行符)匹配。如果没有此修饰符,则将排除换行符。此修饰符相当于Perl的/s修饰符。诸如[^a]之类的负类始终与换行符匹配,与此修饰符的设置无关。
手册中说。