parsing string obtained via cUrl
Posted: Wed Aug 24, 2011 12:21 am
i have this code
what i am trying to do is capture the source of the page and then locate a little bit of text at a particular spot in the source and then upload that data bit to a mysql DB via INSERT, etc
the above seems to be working but where you see my attempt to grab the source and turn it into a string variable obviously isnt working
for the next part of this, how can i grab the source, and turn that into a text string, so i can then properly use the strpos() thing?
any ideas are welcome, thanks!
Code: Select all
<?php
function curl_download($Url){
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_REFERER, "http://www.mysite.org/ref.htm");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$str = curl_download('http://mysite.com');
$mystring = $str;
$findme = 'a';
$pos = strpos($mystring, $findme);
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>
the above seems to be working but where you see my attempt to grab the source and turn it into a string variable obviously isnt working
for the next part of this, how can i grab the source, and turn that into a text string, so i can then properly use the strpos() thing?
any ideas are welcome, thanks!