Quote:
Originally Posted by ProG
I don't entirely understand what you are trying to do but maybe this will help... :shrug:
Code:
$links = '<a rel="nofollow" href="http://www.google.com/" id="extra">google</a>\r\n';
$links .= '<a rel="nofollow" href="http://www.yahoo.com/" id="extra">yahoo</a>\r\n';
$links .= '<a rel="nofollow" href=\'http://www.msn.com/\' id="extra">msn</a>\r\n';
$links .= '<a href="http://www.bing.com/" id="extra">bing</a>\r\n';
$links .= '<a href="http://www.ask.com/" id="extra">ask</a>\r\n';
$uri = 'www.bing.com';
$back = 'bing';
preg_match_all("/<a\s[^>]*href=([\"\']??)(http:\/\/{$uri}*?)([\"\']??)[^>]*>({$back})<\/a>/siU", $links, $matches);
print_r( $matches );
|
That throws an error for me.
Quote:
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '/'
|
This is what I came up with and it works... but it uses a loop.
Code:
<?php
$url = 'http://www.crazyfilth.com';
$anchor_text = 'Crazy Porn';
$html = file_get_contents('http://www.filthdump.com');
echo checkUrl($url, $anchor_text, $html);
function checkUrl($url, $anchor_text, $html) {
$found = false;
$dom = new domDocument();
@$dom->loadHTML($html);
$anchors = $dom->getElementsByTagName('a');
foreach ($anchors as $anchor) {
$found_url = $anchor->getAttribute('href');
$urltext = trim($anchor->nodeValue);
if (($found_url == $url) && ($anchor_text == $urltext)) {
return true;
}
}
return false;
}
?>