etrader Posted January 28, 2011 Share Posted January 28, 2011 I want to get suggested keywords from yahoo api service. When xml file is empty (no keyword), it gives error. To resolve this problem I used this code: if (file_exists('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2')) { $xmlmetades = simplexml_load_file('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2'); } Since it is not a normal .xml file, it is always considered no file, and return nothing. Quote Link to comment https://forums.phpfreaks.com/topic/225947-if-file_exists-for-calling-a-xml-file/ Share on other sites More sharing options...
trq Posted January 28, 2011 Share Posted January 28, 2011 Your probably better off just supressing errors and then checking to see that $xmlmetades is true before using it. $xmlmetades = @simplexml_load_file($file); if ($xmlmetades) { // safe to use } Quote Link to comment https://forums.phpfreaks.com/topic/225947-if-file_exists-for-calling-a-xml-file/#findComment-1166481 Share on other sites More sharing options...
etrader Posted January 28, 2011 Author Share Posted January 28, 2011 Perfect solution Quote Link to comment https://forums.phpfreaks.com/topic/225947-if-file_exists-for-calling-a-xml-file/#findComment-1166657 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.