[英]PHP Simple HTML DOM Parser: How to remove <font> tags from script output?
I'm using PHP Simple HTML DOM Parser to extract a list of URLs from a page as follows: 我正在使用PHP Simple HTML DOM解析器从页面中提取URL列表,如下所示:
<?php
include('simple_html_dom.php');
$url = 'http://www.domain.com/';
$html = file_get_html($url);
foreach($html->find('table[width=370]') as $table)
{
foreach($table->find('a') as $item)
echo $item->outertext . '<br><hr>';
}
$html->clear();
?>
It works just fine insofar as it extracts the required information, however, some of the a tags (on domain.com) are formatted like this: 只要提取所需的信息,它就可以正常工作,但是, 某些 a标记(在domain.com上)的格式如下:
<a href="http://www.domain.com"><font size="2">Anchor text</font></a>
Whereas, in others, the font size is defined in the p tag that contains each a tag, meaning the a tag is displayed as: 而在其他情况下,字体大小是在包含每个标签的p标签中定义的,这意味着该标签显示为:
<a href="http://www.domain.com">Anchor text</a>
Is there any way to strip out the font tag from those a tags that have it? 有什么方法可以从那些拥有字体的标签中删除字体标签? It's probably very simple, but I've been 'running around in rings' for ages trying to do it :( 这可能很简单,但多年来我一直在“四处寻找” :(
Thanks for any ideas or suggestions you might have. 感谢您的任何想法或建议。
Tom. 汤姆
strip_tags() maybe? strip_tags()也许吗?
If you only want to allow the a
tag, just use: 如果你只想让a
标签,只需使用:
echo strip_tags($item->outertext, 'a');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.