Reputation: 23
I need a PHP Google search function, so I tried many function I found in Google, but almost all have the same problem which is they take results directly from Google main URL not from the API URL, which lead after a while to an error because Google detect the visits are from a PHP server and reject any further requests.
So I made my Google search function takes results from Google API URL, and that worked perfectly as you see here #API_URL until I needed to reduce the results buy adding intitle: before the searched keyword, and now the API URL return no result at all as you see here #API_URL.
My question is simple, how do I get results in the Google API URL using this query intitle:maleficent+2014+site:www.anakbnet.com/video/file.php?f= so that I can take Results from it using PHP?
Upvotes: 0
Views: 430
Reputation: 33813
The data you get back from your 'Google API' call is json encoded data so you should try something like the following:-
/* define a constant for ease */
define('BR','<br />');
$data='{"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.anakbnet.com/video/file.php?f\u003d1452","url":"http://www.anakbnet.com/video/file.php%3Ff%3D1452","visibleUrl":"www.anakbnet.com","cacheUrl":"http://www.google.com/search?q\u003dcache:9-JgVUvjnGYJ:www.anakbnet.com","title":"مشاهدة فيلم Alexander and the Terrible اون لاين مباشرة بدون تحميل \u003cb\u003e...\u003c/b\u003e","titleNoFormatting":"مشاهدة فيلم Alexander and the Terrible اون لاين مباشرة بدون تحميل ...","content":"29 كانون الثاني (يناير) 2015 \u003cb\u003e...\u003c/b\u003e مشاهدة فيلم \u003cb\u003eMaleficent 2014\u003c/b\u003e DVD HD مترجم اون لاين مباشرة بدون تحميل اكشن ,مغامرة \n,عائلي .. مشاهدة افلام اجنبية مترجمة اونلاين كاملة. (مشاهدة: 491,605 )."}],"cursor":{"resultCount":"1","pages":[{"start":"0","label":1}],
"estimatedResultCount":"1",
"currentPageIndex":0,
"moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den-GB\u0026q\u003dmaleficent+2014+site:www.anakbnet.com/video/file.php?f%3D",
"searchResultTime":"0.09"}},
"responseDetails": null,
"responseStatus": 200}';
$json=json_decode( $data, true );
$res=(object)$json['responseData']['results'][0];
/* two items extracted from data - use same methodology to get other items */
echo $res->unescapedUrl;
echo $res->cacheUrl;
echo '<pre>';
foreach( $json as $key => $param ){
echo $key.BR;
if( is_array( $param )) $param=(object)$param;
print_r( $param );
}
echo '</pre>';
Hopefully from that you can find what you want?!
Upvotes: 1