dadamssg Posted June 26, 2009 Share Posted June 26, 2009 i want to check if my function is a success or not using bit.ly's API. im using this function i found on the web. 1. /* Example code */ 2. $link = "http://www.x-pose.org"; 3. 4. print getSmallLink($link); 5. 6. function getSmallLink($longurl){ 7. // Bit.ly 8. $url = "http://api.bit.ly/shorten?version=2.0.1&longUrl=$longurl&login=YOURLOGIN&apiKey=YOURAPIKEY&format=json&history=1"; 9. 10. $s = curl_init(); 11. curl_setopt($s,CURLOPT_URL, $url); 12. curl_setopt($s,CURLOPT_HEADER,false); 13. curl_setopt($s,CURLOPT_RETURNTRANSFER,1); 14. $result = curl_exec($s); 15. curl_close( $s ); 16. 17. $obj = json_decode($result, true); 18. return $obj["results"]["$longurl"]["shortUrl"]; 19. } if this snippet goes write i get my bit.ly url and Tweet the results. But sometimes it times out. How would i write something to check if it returned a bit.ly url and if not execute some other code? Link to comment https://forums.phpfreaks.com/topic/163785-how-to-check-for-success-in-curl/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.