你好,
im使用以下代码从URL检索DOM查找所有"A"标签并打印其HREF现在我的输出包含"A",我不想它的输出在这里http://trend.remal.com/parsing.php一些元件重复,我需要清除我的"A",包括https://twitter.com/此处显示$name正如你所看到的,我有两种网址,我只需要twitter网址,避免重复调整代码的任何提示
<?php
include('simple_html_dom.php');
$html = file_get_html('http://tweepar.com/sa/1/');
foreach($html->find('a') as $e)
echo $e->href . '<br>';
?>
$urls = array();
foreach ( $html->find('a') as $e )
{
// If it's a twitter link
if ( strpos($e->href, '://twitter.com/') !== false )
{
// and we don't have it in the array yet
if ( ! in_array($e->href, $urls) )
{
// add it to our array
$urls[] = $e->href;
}
}
}
echo implode('<br>', $urls);
以下是PHP文档中的一些参考:
strpos
in_array
implode