I am working on a research project regarding Bing and it's search results, and since I am still very new to PHP, I am looking for a little bit of help. Yesterday I already got some help here and the result was so great that I am trying once more :)
I have the following code:
<?php
$r = '{"d":{"results":[{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=\u0027web\u0027&Market=\u0027en-US\u0027&Query=\u0027php\u0027&Adult=\u0027off\u0027&$skip=0&$top=1","type":"ExpandableSearchResult"},"ID":"1c509d25-5ca4-4db5-bfc5-cafd6917e2c2","WebTotal":"10600000","WebOffset":"0","ImageTotal":"","ImageOffset":"","VideoTotal":"","VideoOffset":"","NewsTotal":"","NewsOffset":"","SpellingSuggestionsTotal":"","AlteredQuery":"","AlterationOverrideQuery":"","Web":[{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00271c509d25-5ca4-4db5-bfc5-cafd6917e2c2\u0027)/Web?$skip=0&$top=1","type":"WebResult"},"ID":"4cf2a8d6-21b7-433d-81e9-84e74091a44a","Title":"PHP: Hypertext Preprocessor","Description":"What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.","DisplayUrl":"www.php.net","Url":"http://www.php.net/"},{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00271c509d25-5ca4-4db5-bfc5-cafd6917e2c2\u0027)/Web?$skip=48&$top=1","type":"WebResult"},"ID":"2d8f8107-895e-4052-9edc-b656e74c3f2e","Title":"CakePHP: the rapid development php framework. Pages","Description":"Official website. Offers a manual for beginners and links towards the last version.","DisplayUrl":"cakephp.org","Url":"http://cakephp.org/"},{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00271c509d25-5ca4-4db5-bfc5-cafd6917e2c2\u0027)/Web?$skip=49&$top=1","type":"WebResult"},"ID":"816d781c-ff8b-4a60-b5b7-28d807bba28a","Title":"PHP Presents","Description":"Welcome to the PHP Presentation System. Here we list all of the available presentation categories stored within this system.","DisplayUrl":"talks.php.net","Url":"http://talks.php.net/"}],"Image":[],"Video":[],"News":[],"RelatedSearch":[],"SpellingSuggestions":[]}]}}';
$r = json_decode($r);
foreach($r->d->results as $value) {
foreach($value->Web as $result) {
echo $result->Title, "\r\n";
echo $result->Description, "\r\n";
echo $result->Url, "\r\n";
}
}
?>
This basically shows the title, description and URL of the three sites of the json results from Bing (Note: It's not always just 3 results, normally it's 10 but can be any number)
Now here is what my big mission is: For my research project, I need to shuffle the results randomly, meaning I would like to see it for example like:
First time I load the page: CakePHP: the rapid development php framework. Pages PHP Presents PHP: Hypertext Preprocessor
Second time I load the page: PHP Presents PHP: Hypertext Preprocessor CakePHP: the rapid development php framework. Pages
Third time I load the page: PHP: Hypertext Preprocessor CakePHP: the rapid development php framework. Pages PHP Presents
Again, the order above is just an example - I really want it randomly with no specific order.
I would like to thank my previous helpers and I am looking forward to your answers.
Thank you for your time reading this :)
Update: If anyone would be so kind and also show me an example of only shuffling the results except the first three ones - that would be really great.