View Single Post
Old 08-01-2009, 02:07 PM  
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
Quote:
Originally Posted by ProG View Post
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;
}
?>

Last edited by nation-x; 08-01-2009 at 02:10 PM..
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote