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.