jigen7 Posted October 2, 2007 Share Posted October 2, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/71496-solved-helpcant-convert-to-integer-from-string-format/ Share on other sites More sharing options...
trq Posted October 2, 2007 Share Posted October 2, 2007 Have you tried? return (int) $strip; Quote Link to comment https://forums.phpfreaks.com/topic/71496-solved-helpcant-convert-to-integer-from-string-format/#findComment-359925 Share on other sites More sharing options...
jigen7 Posted October 2, 2007 Author Share Posted October 2, 2007 yeah only tried that also.. Quote Link to comment https://forums.phpfreaks.com/topic/71496-solved-helpcant-convert-to-integer-from-string-format/#findComment-359951 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 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) Quote Link to comment https://forums.phpfreaks.com/topic/71496-solved-helpcant-convert-to-integer-from-string-format/#findComment-359967 Share on other sites More sharing options...
jigen7 Posted October 2, 2007 Author Share Posted October 2, 2007 ok ill try that ill post if its works Quote Link to comment https://forums.phpfreaks.com/topic/71496-solved-helpcant-convert-to-integer-from-string-format/#findComment-360315 Share on other sites More sharing options...
jigen7 Posted October 2, 2007 Author Share Posted October 2, 2007 great it works!how did you happen to know that it was returning other value?the span thing?? Quote Link to comment https://forums.phpfreaks.com/topic/71496-solved-helpcant-convert-to-integer-from-string-format/#findComment-360467 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 HeeHee, i'll admit i had me for a second.. but string cause that problem and after viewing source... it became clear Quote Link to comment https://forums.phpfreaks.com/topic/71496-solved-helpcant-convert-to-integer-from-string-format/#findComment-360469 Share on other sites More sharing options...
jigen7 Posted October 3, 2007 Author Share Posted October 3, 2007 aww you have view its actual source code in html?? oh well ill keep that in my mind.. thx man Quote Link to comment https://forums.phpfreaks.com/topic/71496-solved-helpcant-convert-to-integer-from-string-format/#findComment-360519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.