OperaでPHPのマニュアルを簡単に引く。


今日9.26が公開されたOperaのTIP。

PHP: PHP マニュアル - Manualで検索欄の上で右クリックをして、検索の作成を選択するだけ。Operaにマニュアル検索欄が作成される。全文検索と関数検索を作っておけば便利。スピードダイヤル(いわゆるブランクページ)にマニュアル検索欄を作っておくのも便利。

PHPで、ライブドアクリップの登録数を取得。

はてなと全く同じ。

LivedoorBookMark.php

<?php
class LivedoorBookMark 
{

    private $_result;
    private $_word;
    private $_client;

    public function __construct() 
    {

    }

    public function getData($keyword)
    {
        $this->_word = $keyword;
        $this->getXmlRpc();
        return $this->_result;
    }

    private function getXmlRpc()
    {
        require_once 'Zend/XmlRpc/Client.php';
        $this->_client = new Zend_XmlRpc_Client('http://rpc.clip.livedoor.com/count');
        $this->_result = $this->_client->call('clip.getCount', $this->_word);
    }
}

$bookmark = array(
    'http://d.hatena.ne.jp/',
    'http://b.hatena.ne.jp/',
    'http://www.hatena.ne.jp/',
);

require_once 'Zend/Debug.php';
$client = new LivedoorBookMark();
$data = $client->getData($bookmark);
$data = Zend_Debug::dump($data);
$filename = 'bookmark.txt';
file_put_contents($filename, $data);

PHPでYahoo!ディレクトリ取得スクリプト。

このAPIは二種類のエラーを出す。それぞれを記録する。

<?php
class YahooDirectorySearch
{
    private $_data;
    private $_client;
    private $_keyid;
    private $_word;
    private $_logger;
    public function __construct() {
        require_once 'Zend/Log.php';
        require_once 'Zend/Log/Writer/Stream.php';
        $this->_logger = new Zend_Log();
        $writer = new Zend_Log_Writer_Stream('./error.log');
        $this->_logger->addWriter($writer);
    }

    public function getData($word,$key)
    {
        $this->_word = $word;
        $this->_keyid = $key;
        $this->getRest();
        if($this->_result->Message)
        {
            $error_message .= "{$this->_result->Message}";
            $this->_logger->log($error_message, Zend_Log::ERR);
        }
        else
        {
            if ($this->_result->Status->Errors->Error)
            {
                foreach($this->_result->Status->Errors->Error->attributes() as $a => $b)
                {
                    $error_message .= "$a:$b";
                }
                $this->_logger->log($error_message, Zend_Log::ERR);
            }
            else
            {
                foreach($this->_result->SiteSearchResults->attributes() as $a => $b)
                {
                    $this->_data[$a] = "$b";
                }
                foreach($this->_result->SiteSearchResults->Item as $value )
                {
                    $this->_data[Result][] = array(
                        'Title' => "$value->Title",
                        'Summary' => "$value->Summary",
                        'Url' => "$value->Url",
                        'ClickUrl' => "$value->ClickUrl",
                        'New' => "$value->New",
                        'Picks' => "$value->Picks",
                        'Cool' => "$value->Cool"
                    );
                }
            }
        }
        return $this->_data;
    }

    private function getRest()
    {
        require_once 'Zend/Http/Client.php';
        $this->_client = new Zend_Http_Client();
        $this->_client->setUri('http://api.dir.yahoo.co.jp/Category/V1/directorySearch');
        $this->_client->setParameterGet(
            array(
            'appid' => $this->_keyid , 
            'results' => 50 ,
            'type' => 2 ,
            'query' => $this->_word
            )
        );
        $this->_result = $this->_client->request();
        $this->_result = $this->_result->getBody();
        $this->_result = simplexml_load_string($this->_result);
    }
}
require_once 'Zend/Debug.php';
$appid = 'appid';
$word = 'りんご';
$client = new YahooDirectorySearch();
$data = $client->getData($word,$appid);
$data = Zend_Debug::dump($data);
$filename = 'dir.txt';
file_put_contents($filename, $data);