这是我到目前为止编写的代码:
foreach ($link_body as $key => $unfinished_link)
{
#further Remove non ad links
if (stristr($unfinished_link, "inactive" OR "nofollow") === TRUE)
{
unset($link_body[$key]);
}
echo "<font color='#FFFFFF' size='16'>$unfinished_link</font><br>";
}
我没有收到任何错误消息,但一直得到如下所示的结果:
/cars/" />
/cars/">
/cars/" class="inactive">(not what I wanted)
/cars/" class="inactive">(not what I wanted)
/cars/" class="inactive">(not what I wanted)
/cars/" rel="nofollow">(not what I wanted)
/cars/?layout=gallery" rel="nofollow">(not what I wanted)
/cars/2001-ford-escort-great-condition/1235588">(IS what I wanted)
伙计们,我在哪里弄糟?谢谢
如果您想在其中找到一个字符串,也许您会喜欢使用stripos
:
foreach ($link_body as $key => $unfinished_link) {
// further Remove non ad links
if(
stripos($unfinished_link, 'inactive') !== false ||
stripos($unfinished_link, 'nofollow') !== false
) {
unset($link_body[$key]);
} else {
echo "<font color='#FFFFFF' size='16'>$unfinished_link</font><br>";
// make sure your background is not white, or else your text will not be seen, at least on the white screen
}
}
如果这是HTML标记,请特别考虑使用HTML解析器DOMDocument
,并搜索该属性:
$rel = $node->getAttribute('rel'); // or
$class = $node->getAttribute('class');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句