I have tried parsing a website with curl and then searching it with regular expressions, but I have not been able to perform a regex search. Even if I try parsing news.google.com and then search for any non digit, the code returns that there is no match.

If I run a regex search on a simple inputted string, on the other hand, it does find a match with no problem.

<?

//source website
$source = "http://news.google.com/?topic=w";

//function to parse with cURL
function openWithCURL($url){
 	$curl_handle=curl_init();
	curl_setopt($curl_handle,CURLOPT_URL, $url);
	$result = curl_exec($curl_handle);
	curl_close($curl_handle);
}


// parse website
$parsedsite = openWithCURL($source);

//Regular Expression to search for any single non digit (made it very inclusive so as to test out whether the regular expression works)

$regexp="/\D/";

if (preg_match($regexp, $parsedsite, $matches)) {
	echo "Found it!!";
	echo $matches[0];
}
	else {
	echo "Didn't find it!!";
}

?>

Any assistance in determining why I cannot seem to use regular expressions on information parsed from a webpage using curl would be greatly appreciated. Thanks.

Your openWithCURL function doesn't return anything.
I suppose you want

function openWithCURL($url){
 	$curl_handle=curl_init();
	curl_setopt($curl_handle,CURLOPT_URL, $url);
	$result = curl_exec($curl_handle);
	curl_close($curl_handle);
	return $result;
}

Thanks, I had originally had the function just as you say, set to

return $results

. However, I just tried modifying the script to add the return value back in, and the regular expression still doesn't work.

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.