REGEX(.*)和换行符

sim*_*ple 1 php regex newline

我怎样才能解决这个问题?

REGEX:
//REGEX
$match_expression = '/Rt..tt<\/td> <td>(.*)<\/td>/';
preg_match($match_expression,$text,$matches1);
$final =  $matches1[1];       


//THIS IS WORKING
<tr> <td class="rowhead vtop">Rtštt</td> <td><img border=0 src="http://somephoto"><br /> <br />INFO INFO INFO</td>
</tr> 


//THIS IS NOT WORKING
<tr> <td class="rowhead vtop">Rtštt</td> <td> <br />
IFNO<br />
INFO<br /></td></tr>
Run Code Online (Sandbox Code Playgroud)

And*_*ore 5

这正是您不应该使用正则表达式从HTML文档中提取数据的原因.

标记结构是如此随意,以至于它太不可靠,这正是为什么我不会给你一个正确的正则表达式,因为没有(其他用户提供的解决方案可能会工作......直到它们中断).使用像DOMDocumentphpQuery这样的DOM解析器从文档中提取数据.

这是一个使用phpQuery的例子:

$pq = phpQuery::newDocumentFile('somefile.html');
$rows = $pq->find('td.rowhead.vtop:parent');

$matches = array();

foreach($rows as $row) {
  $matches[] = $row->eq(1)->html();
}
Run Code Online (Sandbox Code Playgroud)