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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.