Jump to content

[SOLVED] HELP!Cant convert to integer from string format!!!


jigen7

Recommended Posts

can anyone help me here....i have here a function that gets the # of linkdomain in yahoo using CURL then use a preg_match pattern to get the actual value ok the problem is the return value is a string format that i cant convert to in, i have tried using the (int) and intval($string) thing but they only make the value become zero whats the problem??

 

function yahoo_linkdomain($url){

 

$ch = curl_init();

$url = preg_replace("/^(http:\/\/)?([^\/\?]+)([\/|\?])?(.+)?$/", "\$2\n", $url);

 

curl_setopt($ch, CURLOPT_URL, 'http://search.yahoo.com/search?ei=UTF-8&fr=sexp-rd&p=linkdomain%3A'.urlencode($url).'+-site%3A'.urlencode($url));

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_FILETIME, true);

$total = curl_exec($ch);

 

 

curl_close($ch);

$match_expression = '/of (.*) for/Us'; 

preg_match($match_expression,$total,$matches); 

$strip = str_replace(",","",$matches[1]); 

return $strip;

 

}

 

$strip is the value that i want to convert to int which is giving me a hard time because i dont know the problem why cant it be converted

The RegEx is wrong

 

your returning

<span id="infototal">61300</span>

 

try this

<?php

$X = yahoo_linkdomain("test.com");
$X = (int)$X;
var_dump($X);



function yahoo_linkdomain($url){

$ch = curl_init();
$url = preg_replace("/^(http:\/\/)?([^\/\?]+)([\/|\?])?(.+)?$/", "\$2\n", $url);

curl_setopt($ch, CURLOPT_URL, 'http://search.yahoo.com/search?ei=UTF-8&fr=sexp-rd&p=linkdomain%3A'.urlencode($url).'+-site%3A'.urlencode($url));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FILETIME, true);
$total = curl_exec($ch);


curl_close($ch);
if (preg_match('%<span id="infototal">([\d,]*)</span>%si', $total, $regs)) {
	$strip = preg_replace('/,/', '', $regs[1]); //remove commas, could add (int) here if you want!
}
   return $strip;
   
}
?>

int(61300)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.