How to add Yahoo API code to this code?

Please help me How to add Yahoo API code to this code?

<?php

$query = "site:mixx.com+linkdomain:cnet.com";

preg_match("/<strong id=\\"resultCount\\">([0-9,]*)<\\/strong> results for<\\/span>/", file_get_contents("http://uk.search.yahoo.com/search?p=".$query), $matches);

$numberofresults = $matches[1];

echo $numberofresults;
?>

Yahoo is a company. There is no such thing as a “Yahoo API”. Their products have APIs. What exactly are you trying to do?


function get_yahoo_search_result_count($query){
    
    $dom = @DOMDocument::loadHTMLFile(
        sprintf(
            'http://uk.search.yahoo.com/search;_ylt=?p=&#37;s&fr=sfp&fr2=&iscqry=',
            urlencode($query)
        )
    );
    
    if(false === $dom){
        return false;
    }
    
    $xpath = new DOMXPath($dom);
    
    $result = $xpath->query("//strong[@id='resultCount']");
    
    if(0 === $result->length){
        return false;
    }
    
    return (string)$result->item(0)->nodeValue;
}

echo get_yahoo_search_result_count('sitepoint'); #5,180,000

Thanks for your code.
deference between your code and my code?

It works? :stuck_out_tongue:

Yahoo has limitation 999 req/day.
for AVOID of limitation must used yahoo api code.

Yahoo! has many APIs, you’ll probably want to use BOSS (Build your Own Search Service).

A very quick and basic example looks like:


$search = 'yahoo boss example';

// Get your App ID from https://developer.apps.yahoo.com/wsregapp/
$appid = '058Q0srV34FFO3r1qJWa4vzhMggarrR3fDUzm8bH5QfylNUaOAtUp33s6qFnmtt3';
$apiurl = 'http://boss.yahooapis.com/ysearch/web/v1/' . urlencode($search) . '?appid=' . urlencode($appid);

// Fetch and decode search results
$json = file_get_contents($apiurl);
$data = json_decode($json, TRUE);
$result_count = $data['ysearchresponse']['totalhits'];

// Tell it like it is: Found 446,413 results for "yahoo boss example".
echo 'Found ' . number_format($result_count) . ' results for "' . $search . '".';

Thanks Salathe.
How to use your code for this query (site:jumptags.com linkdomain:cnet.com)?

Just change the $search variable to contain your required search phrase:

$search = 'site:jumptags.com linkdomain:cnet.com';

This code not worked for me.

<? php
$search = 'yahoo boss example';

// Get your App ID from https://developer.apps.yahoo.com/wsregapp/

$appid = '058Q0srV34FFO3r1qJWa4vzhMggarrR3fDUzm8bH5QfylNUaOAtUp33s6qFnmtt3';

$apiurl = 'http://boss.yahooapis.com/ysearch/web/v1/' . urlencode($search) . '?appid=' . urlencode($appid);



// Fetch and decode search results

$json = file_get_contents($apiurl);

$data = json_decode($json, TRUE);

$result_count = $data['ysearchresponse']['totalhits'];



// Tell it like it is: Found 446,413 results for "yahoo boss example".

echo 'Found ' . number_format($result_count) . ' results for "' . $search . '".'; 

?>

my yahoo App ID:

Congratulations, karimian61, your application is now registered! Yeah!

    * Your application id is EloAStvIkY2GDBJ1c4OkSgvH9zFNwyGvjr4-
    * Your shared secret is 8800b5727ab3ec3b2b76f22da7bce290
    * For application entrypoint -> http://mysiteevaluate.com/website.php 

Please help me.
i am BEGINNER in PHP Programming.

What makes you say that it does not work? It is best to give us as much information as possible since scripts can “not work” for many, many reasons! Does it give any errors? Anything at all?

Off Topic:

P.S. Please don’t PM me every time you reply. It is irritating! I browse the forums for replies regularly throughout the day, on my own schedule and will get to your replies eventually. :eye:

Salathe Excuse for sending pm.
I have this error :

Parse error: syntax error, unexpected T_VARIABLE in /home/mysitee/public_html/1.php  on line 2

For this code:

<? php
$search = 'yahoo boss example';



// Get your App ID from https://developer.apps.yahoo.com/wsregapp/

$appid = '058Q0srV34FFO3r1qJWa4vzhMggarrR3fDUzm8bH5QfylNUaOAtUp33s6qFnmtt3';

$apiurl = 'http://boss.yahooapis.com/ysearch/web/v1/' . urlencode($search) . '?appid=' . urlencode($appid);



// Fetch and decode search results

$json = file_get_contents($apiurl);

$data = json_decode($json, TRUE);

$result_count = $data['ysearchresponse']['totalhits'];



// Tell it like it is: Found 446,413 results for "yahoo boss example".

echo 'Found ' . number_format($result_count) . ' results for "' . $search . '".'; 

?>

Did you even try to solve this on your own? Do you even know PHP syntax?

There should be no space between <? and php. Your file should start with:

<?php

Edit: Oops AlienDev posted at the same time as me. Ah well, you’ve been doubly told. :eye:

How to replace cnet.com with <? echo $website; ?>



<? php
$search = 'site:jumptags.com linkdomain:cnet.com'; 
// Get your App ID from https://developer.apps.yahoo.com/wsregapp/
$appid = '058Q0srV34FFO3r1qJWa4vzhMggarrR3fDUzm8bH5QfylNUaOAtUp33s6qFnmtt3';
$apiurl = 'http://boss.yahooapis.com/ysearch/web/v1/' . urlencode($search) . '?appid=' . urlencode($appid);
// Fetch and decode search results
$json = file_get_contents($apiurl);
$data = json_decode($json, TRUE);
$result_count = $data['ysearchresponse']['totalhits'];
// Tell it like it is: Found 446,413 results for "yahoo boss example".
echo 'Found ' . number_format($result_count) . ' results for "' . $search . '".'; 
?>

$search = ‘site:jumptags.com linkdomain:’.$website;

in Yahoo:

Welcome to the Developer Network.
Registration Complete

Congratulations, karimian61, your application is now registered! Yeah!

* Your application id is EloAStvIkY2GDBJ1c4OkSgvH9zFNwyGvjr4-
* Your shared secret is [[SECRET STRING]]
* For application entrypoint -&gt; http://xxx.com/website.php 

and for $appid = ‘058Q0srV34FFO3r1qJWa4vzhMggarrR3fDUzm8bH5QfylNUaOAtUp33s6qFnmtt3’;

please help me is true
for my $appid = ‘EloAStvIkY2GDBJ1c4OkSgvH9zFNwyGvjr4-’;

Read this

my question and code not secret.

please help me is true
for my $appid = ‘EloAStvIkY2GDBJ1c4OkSgvH9zFNwyGvjr4-’;