PHP从html解析一些代码

标签 php html parsing rss

我在用 PHP 解析 Google 新闻 RSS 时遇到困难。 XML 描述包含很多困惑,我只需要其中的 2 个小部分,但我不知道如何只提取我想要的部分。我一直在尝试使用 PHP preg_macth,但没有成功。

请看下面的代码,我已经在文本中添加了我要获取的部分的注释。

附言。抱歉,这看起来有点乱,但这就是谷歌新闻 rss 的样子:

<table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;">
<tr>
<td width="80" align="center" valign="top">
<font style="font-size:85%;font-family:arial,sans-serif">
    <a href="http://">
    <!-- i need only this img src only -->
    <img src="http://nt3.ggpht.com/news/tbn/ExvkIyaCiPpZwM/6.jpg" /><br />
    <!-- /till here -->
    <font size="-2">Moneycontrol.com</font></a>
</font>
</td>

<td valign="top" class="j"><font style="font-size:85%;font-family:arial,sans-serif"><br />

<div style="padding-top:0.8em;">
<img alt="" height="1" width="1" /></div>
<div class="lh">

    <a href="http://">
    <b>Microsoft&#39;s Office 365 to take on Google Apps in cloud software race</b>
    </a><br />

<font size="-1">
    <b><font color="#6f6f6f">Los Angeles Times</font></b>
</font><br />

<font size="-1">
<!----------------- i need only the following text ----------->
Microsoft Corp., the 800-pound gorilla of the software world, is hoping it can lift itself into the cloud. In announcing the general release of Office 365, the online version of its ubiquitous Microsoft Office suite that includes Word, <b>...</b>
<!------------------------- -till here ------------------>
</font><br />

<font size="-1">
    <a href="http://">Office 365: Microsoft Pitches Cloud, Eyes Profit</a>
    <font size="-1" color="#6f6f6f"><nobr>InformationWeek</nobr></font>
</font>
<br />

<font size="-1">
    <a href="http://">Microsoft Battles for Sky Supremacy With Office 365 Launch</a>
    <font size="-1" color="#6f6f6f"><nobr>TechNewsWorld</nobr></font>
</font><br />
...

非常感谢您花宝贵的时间阅读本文并帮助我。

最佳答案

不确定这是否有帮助,但您可以查看 PHP 函数“strip_tags”

关于PHP从html解析一些代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6513379/

相关文章:

php - 使用学说选择日期时间之间的行

php - 使用 Jquery(ajax) 防止页面重新加载的最佳方法是什么?

html - 媒体查询在桌面上不起作用

php - 是否有工具或简单的 PHP 或 Jquery 解决方案可以将所有 id 和类导出到空白的 css 表中?

sql-server - 在 SQL Server 2005 中解析 QueryString

php - 检查更新查询是否成功[PHP, mysqli]

javascript - 如何用 jQuery 删除元素?

html - CSS : Label/Textbox not displaying inline correctly

json - 将 JSON 解析为哈希表

python - 使用 PLY 解析逻辑表达式