在HTML标签之间预匹配php中的文本

问题描述:

您好,我想在PHP中使用preg_match来解析html文档中以下内容中的所需文本"

Hello I would like to use preg_match in PHP to parse the "Desired text" out of the following from a html document

<p class="review"> Desired text </p>

通常,我将使用simple_html_dom进行此类操作,但在这种情况下无法使用(上述元素并未出现在每个所需的div标签中,因此我*使用这种方法来准确地跟踪何时不使用它.出现,然后相应地从simple_html_dom调整我的数组.)

Ordinarily I would use simple_html_dom for such things but on this occasion it cannot be used (the above element doesn't appear in every desired div tag so I'm forced to use this approach to keep track of exactly when it doesn't appear and then adjust my array from simple_html_dom accordingly).

无论如何,这将解决我的问题.

Anyway, this would solve my problem.

非常感谢.

preg_match("'<p class=\"review\">(.*?)</p>'si", $source, $match);
if($match) echo "result=".$match[1];