etrader Posted January 5, 2011 Share Posted January 5, 2011 With this link http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2 , one can see suggested keywords for a query. The result is like "madonna 4 minutes madonna 4 minutes lyrics". How to put the resulting keywords in a $array, as can be used for further php coding. :-\ Quote Link to comment Share on other sites More sharing options...
nderevj Posted January 5, 2011 Share Posted January 5, 2011 What about: $contents = file_get_contents('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2'); $dataArray = implode(' ', $contents); You might need to urlencode that address: $uri = urlencode('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2'); $contents = file_get_contents($uri); ... Quote Link to comment Share on other sites More sharing options...
etrader Posted January 5, 2011 Author Share Posted January 5, 2011 I get this error Warning: file_get_contents(http%3A%2F%2Fsearch.yahooapis.com%2FWebSearchService%2FV1%2FrelatedSuggestion%3Fappid%3DYahooDemo%26query%3DMadonna%26results%3D2) [function.file-get-contents]: failed to open stream: No such file or directory in and this one Warning: implode() [function.implode]: Invalid arguments passed in Quote Link to comment Share on other sites More sharing options...
nderevj Posted January 5, 2011 Share Posted January 5, 2011 Yep, my mistake. Turns out the url actually points to an XML document. This should give you some insight: $xml = simplexml_load_file('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2'); var_dump($xml); Quote Link to comment Share on other sites More sharing options...
nderevj Posted January 5, 2011 Share Posted January 5, 2011 $dataArray = array(); $xml = simplexml_load_file('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2'); foreach($xml->Result as $result) { $dataArray = array_merge($dataArray, explode(' ', (string) $result)); } $dataArray = array_unique($dataArray); // Remove this line if you want duplicate values. Quote Link to comment Share on other sites More sharing options...
etrader Posted January 5, 2011 Author Share Posted January 5, 2011 Thanks! It works perfectly Quote Link to comment 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.