Member Avatar for michelleradu

Hi all
I'm trying to built a function which will check if a given url and linktext exists on another given webpage.
This is what I've done so far using regular expressions:

function islinking($linkurl,$linktext,$clienturl)
  {
    $curl = curl_init($linkurl);
	curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	$file = curl_exec($curl);
	curl_close($curl);
                $s=0;
	preg_match_all('/<a[^>]*?href=[\'"]'.gethost($clienturl).'[\'"][^>]*?>'.$linktext.'<\/a>/si',$file,$matches);
	$matches = $matches[0];
	$s=count($matches);
	if ($s>0) return true;
	 else return false;
  }

The function should return true if the clienturl and the linktext were found on the linkurl page, but it only returns false.
I'm not very good with regular expressions, any help is appreciated.

Recommended Answers

All 2 Replies

What does gethost($clienturl) return ? If it contains forward slashes the unexpected result can be explained, because they need to be escaped.

Member Avatar for michelleradu

What does gethost($clienturl) return ? If it contains forward slashes the unexpected result can be explained, because they need to be escaped.

function getHost($Address)
 { 
    $parseUrl = parse_url(trim($Address)); 
    return trim($parseUrl[host] ? $parseUrl[host] : array_shift(explode('/', $parseUrl[path], 2))); 
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.