php preg match-如何获取html标记?
有很多线索,但我仍然需要帮助。 我需要使用preg_match从HTML标记中获取所需的文本 HTML是:php preg match-如何获取html标记?,php,html,regex,tags,preg-match,Php,Html,Regex,Tags,Preg Match,有很多线索,但我仍然需要帮助。 我需要使用preg_match从HTML标记中获取所需的文本 HTML是: <td> <center> <b> <font face="Arial" color="red">(I need this content)</font> </b> </center> </td> (我需要这个内容) (顺便说一句,我解决了domdocument的问题,但我需要使用preg
<td>
<center>
<b>
<font face="Arial" color="red">(I need this content)</font>
</b>
</center>
</td>
(我需要这个内容)
(顺便说一句,我解决了domdocument的问题,但我需要使用preg_match)
请帮忙
问候。这是什么
<?php
$html = '<td>
<center>
<b>
<font face="Arial" color="red">(I need this content)</font>
</b>
</center>
</td>';
$matches = array();
preg_match_all('/<font.*?>(.*?)<\/font>/is', $html, $matches);
var_dump($matches[1]);
您要查找的文本是只会出现在标记中,还是可以出现在任何地方?如果你知道文本将出现在一般区域,你可以使用strip_tags
删除所有HTML并留下所需文本。是的,这不是我的代码,这样我需要从旧网站获取数据。不幸的是,我仍然得到空数组/真奇怪。我发布的代码很有用。。。(我已经在本地进行了测试)。