php preg_匹配,两个div值之间的get

php preg_匹配,两个div值之间的get,php,regex,preg-match,Php,Regex,Preg Match,我怎样才能得到这篇文章的价值呢。 想法: 年份:2012年 公里:69.000 颜色:蓝色 价格:29.9000 preg_match('@</div></td><td class=\"searchResultsAttributeValue\">(.*?)<\/td>@si',$string,$val); $string = "<div class="classifiedSubtitle">Opel > Astra >

我怎样才能得到这篇文章的价值呢。 想法: 年份:2012年 公里:69.000 颜色:蓝色 价格:29.9000

preg_match('@</div></td><td
 class=\"searchResultsAttributeValue\">(.*?)<\/td>@si',$string,$val);

 $string = "<div class="classifiedSubtitle">Opel > Astra > 1.4 T Sport</div>
</td>
            <td class="searchResultsAttributeValue">
                    2012</td>
            <td class="searchResultsAttributeValue">
                    69.000</td>
            <td class="searchResultsAttributeValue">
                    Blue</td>
            <td class="searchResultsPriceValue">
                        <div> $ 29.900 </div></td>
                <td class="searchResultsDateValue">
                        <span>21 Nov</span>
                        <br/>
                        <span>2016</span>
                    </td>
                <td class="searchResultsLocationValue">
                        USA<br/>Texas</td>"
preg_match('@(.*)@si',$string,$val);
$string=“欧宝>阿斯特拉>1.4吨运动版
2012
69
蓝色
$ 29.900 
11月21日

2016 美国
德克萨斯州“
最好的解决方案不是使用正则表达式。你应该用Dom来做

$dom = new DOMDocument();
$dom->loadHTML($string);
$xPath = new DOMXpath($dom);
$tdValue = $xPath->query('//td[@class="searchResultsAttributeValue"]')->get(0)->nodeValue;
通过这种方式,您将使用类
searchResultsAttributeValue
获得td元素。当然,您应该验证这个元素是否真的存在,以及其他一些验证,但这就是方法


希望我能有所帮助。

,使用insteadFirst您需要用单引号封装
$string
,或者转义属性使用的双引号。这里有一个更接近的正则表达式,但仍然会失败,因此您应该使用解析器,
\s*\s*(.*)
。您还应该格式化问题的
想法:
部分。可能的重复