Php 具有多个结果的正则表达式问题
我正在做一些php html解析,这是我现在拥有的代码Php 具有多个结果的正则表达式问题,php,regex,dom,Php,Regex,Dom,我正在做一些php html解析,这是我现在拥有的代码 function get_tag($htmlelement,$attr, $value, $xml ,$arr) { $attr = preg_quote($attr); $value = preg_quote($value); if($attr!='' && $value!='') { $tag_regex = '/<'.$htmlelement.'[^>]*'.$att
function get_tag($htmlelement,$attr, $value, $xml ,$arr) {
$attr = preg_quote($attr);
$value = preg_quote($value);
if($attr!='' && $value!='')
{
$tag_regex = '/<'.$htmlelement.'[^>]*'.$attr.'="'.$value.'">(.*?)<\\/'.$htmlelement.'>/si';
preg_match($tag_regex,$xml,$matches);
}
else
{
$tag_regex = '/'.$htmlelement.'[^>]*"(.*?)\/'.$htmlelement.'/i';
preg_match_all($tag_regex,$xml,$matches);
}
if($arr)
return $matches;
else
return $matches[1];
}
$htmlcontent = file_get_contents("doc.html");
$extract = get_tag('tbody','id', 'open', $htmlcontent,false);
$trows = get_tag('tr','', '', $htmlcontent,false);
函数get_标记($htmlelement、$attr、$value、$xml、$arr){
$attr=预报价($attr);
$value=预报价($value);
如果($attr!=''&&$value!='')
{
$tag_regex='/]*'.$attr'='.$value'.'>(.*)/si';
preg_match($tag_regex,$xml,$matches);
}
其他的
{
$tag_regex='/'.$htmlelement.[^>]*“(.*?\/'.$htmlelement./i';
preg_match_all($tag_regex,$xml,$matches);
}
如果($arr)
返回$matches;
其他的
返回$matches[1];
}
$htmlcontent=文件获取内容(“doc.html”);
$extract=get_标记('tbody','id','open',$htmlcontent,false);
$trows=get_标记('tr','',$htmlcontent,false);
必须解析的行/$extract中的内容可以在此处查看
基本上,我是在阅读html内容并从html中获取标记tbody。现在我想在tbody中获取每个tr和td值并在我的页面中使用。如果知道如何使用,我认为我没有使用正确的方法来实现preg_match_all。请使用PHP,而不是正则表达式
快速方法:
- 在HTML中加载
- 获取
标签t车身
- 获取内的
标记tr