Aralık 30, 2017

Google Öneri Kelimeler Botu

Aramak istediğiniz kelimeye ait tüm sonuçlar için;

header('Content-type: text/html; charset="UTF-8"');
function recursive_func($q, $filter_terms) {
    $terms = [];
    $filter_terms[] = $q;
    $filter_terms = array_unique($filter_terms);

    $google = 'http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=' . urlencode($q);
    $baglanti = file_get_contents($google);
    preg_match_all('#<suggestion data="(.*?)"/>#Ssie',$baglanti,$suggetions);

    if(count($suggetions[1]) > 1) {
        foreach ($suggetions[1] as $suggetion){
            $suggetion = iconv('ISO-8859-9', 'UTF-8', $suggetion);
            if($suggetion != $q && in_array($suggetion, $filter_terms) === false) {
                $term = [];
                $term['name'] = $suggetion;
                $term['child'] = recursive_func($suggetion, $filter_terms);
                $terms[] = $term;
            }

        }
    }
    //print_r($terms);
    return $terms;
}
$results = recursive_func('okey oyna', []);
print_r($results);

Fakat öne çıkan ilk kelimeleri çekmek için ise,

header('Content-type: text/html; charset="UTF-8"');
function recursive_func2($q, $filter_terms) {

    $terms = [];

    $filter_terms[] = $q;
    $filter_terms = array_unique($filter_terms);

    $google = 'http://suggestqueries.google.com/complete/search?output=toolbar&hl=tr&q=' . urlencode($q);
    $baglanti = file_get_contents($google);
    preg_match_all('#<suggestion data="(.*?)"/>#Ssie',$baglanti,$suggetions);

    if(count($suggetions[1]) > 1) {
        $suggetion = iconv('ISO-8859-9', 'UTF-8', $suggetions[1][1]);

        if($suggetion != $q && in_array($suggetion, $filter_terms) === false) {
            $term = [];
            $term['name'] = $suggetion;
            $term['child'] = recursive_func2($suggetion, $filter_terms);

            $terms[] = $term;
        }
    }
    //print_r($terms);
    return $terms;

}
$results = recursive_func2('oyunlar', []);
print_r($results);
die;

 

You may also like...

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir


Fatal error: Uncaught Error: Call to undefined method Ressio_HtmlOptimizer_Dom_Element::addChild() in /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/htmloptimizer/dom.php:182 Stack trace: #0 /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/plugin/widgets/widgets.php(66): Ressio_HtmlOptimizer_Dom->appendScriptDeclaration('!function(e,t,n...', Array, Object(Ressio_HtmlOptimizer_Dom_Element)) #1 /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/plugin/widgets/widgets.php(151): Ressio_Plugin_Widgets->injectJsLoader(Object(Ressio_HtmlOptimizer_Dom), Object(Ressio_HtmlOptimizer_Dom_Element)) #2 /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/dispatcher.php(117): Ressio_Plugin_Widgets->onHtmlIterateTagSCRIPTBefore(Object(Ressio_Event), Object(Ressio_HtmlOptimizer_Dom), Object(Ressio_HtmlOptimizer_Dom_Element)) #3 /home/altiltoy/siteler/serdarakyol.com/wp-content in /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/htmloptimizer/dom.php on line 182