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. :-\ Link to comment https://forums.phpfreaks.com/topic/223453-write-from-a-url-to-array-yahoo-keyword-suggestion/ 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); ... Link to comment https://forums.phpfreaks.com/topic/223453-write-from-a-url-to-array-yahoo-keyword-suggestion/#findComment-1155080 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 Link to comment https://forums.phpfreaks.com/topic/223453-write-from-a-url-to-array-yahoo-keyword-suggestion/#findComment-1155083 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); Link to comment https://forums.phpfreaks.com/topic/223453-write-from-a-url-to-array-yahoo-keyword-suggestion/#findComment-1155084 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. Link to comment https://forums.phpfreaks.com/topic/223453-write-from-a-url-to-array-yahoo-keyword-suggestion/#findComment-1155087 Share on other sites More sharing options...
etrader Posted January 5, 2011 Author Share Posted January 5, 2011 Thanks! It works perfectly Link to comment https://forums.phpfreaks.com/topic/223453-write-from-a-url-to-array-yahoo-keyword-suggestion/#findComment-1155103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.