Simple Curl Issue.... I'm cross eyed at this point.

Status
Not open for further replies.

stmadeveloper

New member
Aug 30, 2007
1,687
36
0
Been a long day - arguing with curl for the last hour. This simple function just isn't working. $url is populated properly (echo's out what it's supposed to (first thing tested). If I hardcode the $url value this works. ie - $url = 'http://www.pagename.php'; this works just fine.

Code:
function get_ezinebody($url)
{
echo $url;  ////(this is echoing out)
//unique text to determine start goes here
$start = '<div id="body">';
//insert end text here
$end = "<div><p>Article Source:";
//give credit to the originator
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch) or die ("Couldn't connect to
$url.");
curl_close ($ch);
$startposition = strpos($result,$start);
if($startposition > 0){ 
  $endposition = strpos($result,$end, $startposition);
  //add enough chars to include the tag
  $endposition += strlen($end);
  $length = $endposition-$startposition;
  $result = substr($result,$startposition,$length);
  echo $result;

}
}

What the hell am I missing?
 


What's the $url like when it gets passed to the function?

what I mean is could the $url possibly have whitespace or issues with unescaped characters?
 
Example:

Fishing Boats

If I echo it out - it's that. It's the same url I hardcode in as well. There is no open spaces or anything like that.

Here's the full snippet - including it's call.

Code:
function get_ezinebody($url)
{
echo $url;  ////(this is echoing out)
//unique text to determine start goes here
$start = '<div id="body">';
//insert end text here
$end = "<div><p>Article Source:";
//give credit to the originator
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch) or die ("Couldn't connect to
$url.");
curl_close ($ch);
$startposition = strpos($result,$start);
if($startposition > 0){ 
  $endposition = strpos($result,$end, $startposition);
  //add enough chars to include the tag
  $endposition += strlen($end);
  $length = $endposition-$startposition;
  $result = substr($result,$startposition,$length);
  echo $result;

}
}

echo "$ezineurl";  // Just to verify value is here (it is)

get_ezinebody($ezineurl);
 
This probably has nothing to do with whatever the problem is that you're having... but when you use a $variable inside of a double-quoted string, use { } around it. "{$variable}"
 
class curl{
function curlinit_raw($ch,$session=1,$cookie=null)
{

//set my cookie
if($cookie==null)
{
$cookie='/var/www/system/cookies/'.uniqid().'.cook';
}

curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_TIMEOUT,15);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 5.5; AOL 9.0; Windows NT 5.0; DigExt; FunWebProducts)');
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);
curl_setopt($ch,CURLOPT_COOKIESESSION,$session);

return($cookie);
}

function curlget($ch,$url,$ref)
{
curl_setopt($ch,CURLOPT_POST,0);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_REFERER,$ref);
$s=curl_exec($ch);
return($s);
}

function getgoogle()
{
$ch=curl_init();
$this->curlinit_raw($ch);
$s=$this->curlget($ch,'http://google.com/','');
return($s);
}
}
 
Status
Not open for further replies.