本文整理汇总了PHP中Zend_Rest_Client::format方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Rest_Client::format方法的具体用法?PHP Zend_Rest_Client::format怎么用?PHP Zend_Rest_Client::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Rest_Client
的用法示例。
在下文中一共展示了Zend_Rest_Client::format方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
function search()
{
// load Zend classes
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Rest_Client');
// define category prefix
$prefix = 'hollywood';
// initialize REST client
$wikipedia = new Zend_Rest_Client('http://en.wikipedia.org/w/api.php');
// set query parameters
$wikipedia->action('query');
$wikipedia->list('allcategories');
//All list queries return a limited number of results.
$wikipedia->acprefix($prefix);
$wikipedia->format('xml');
// perform request and iterate over XML result set
$result = $wikipedia->get();
//echo "<ol>";
foreach ($result->query->allcategories->c as $c) {
//<a href="http://www.wikipedia.org/wiki/Category:
echo $c . "<br>";
}
}
示例2: wiki
/**
* rest-client.docx
* Gets the first wiki-text before the Table of Content
* @author TSCM
* @since 20150102
* @param string - a Name or Booktitle , exp: "Lord of the Rings"
* @return string - html code line
* Explanation
* //Base Url:
* http://en.wikipedia.org/w/api.php?action=query
*
* //tell it to get revisions:
* &prop=revisions
*
* //define page titles separated by pipes. In the example i used t-shirt company threadless
* &titles=whatever|the|title|is
*
* //specify that we want the page content
* &rvprop=content
*
* //I want my data in JSON, default is XML
* &format=json
*
* //lets you choose which section you want. 0 is the first one.
* &rvsection=0
*
* //tell wikipedia to parse it into html for you
* &rvparse=1
*
* //only geht the "first"-Description of the wikipage, the one before the Table of Contents
* &exintro=1
*
* //if I want to select something, I use action query, update / delete would be different
* &action=query
*/
public static function wiki($query)
{
// load Zend classes
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Rest_Client');
$decodeUtf8 = 0;
//is decoding needed? Default not
// define search query
$wikiQuery = str_replace(" ", "_", $query);
try {
//initialize REST client
$lang = I18n::lang();
$wikiLang = strtolower($lang);
$webPagePrefix = "http://";
$webPageUrl = ".wikipedia.org/w/api.php";
//build the wiki api. be sure, that $wikiLang exists, exp: de or en
$wikipedia = new Zend_Rest_Client($webPagePrefix . $wikiLang . $webPageUrl);
$wikipedia->action('query');
//standard action, i want to GET...
$wikipedia->prop('extracts');
//what do i want to extract? page info
$wikipedia->exintro('1');
// only extract the intro? (pre-Table of content) 1= yes, 0=now
$wikipedia->titles($wikiQuery);
//title is the wiki title to be found
$wikipedia->format('xml');
//what format should be returned? exp: json, txt, php,
$wikipedia->continue('');
//has to be set, otherwise wikimedia sends a warning
// perform request
// iterate over XML result set
$result = $wikipedia->get();
//print_r($result);
$rs = $result->query->pages->page->extract;
if ($decodeUtf8) {
$rs = utf8_decode($rs);
}
//strip html Tags to get a clean string
$rsFinal = strip_tags($rs);
return $rsFinal;
} catch (Exception $e) {
die('ERROR: ' . $e->getMessage());
}
}
示例3: catch
// instantiate a Text_Wiki object from the given class
// and set it to use the Mediawiki adapter
$wiki =& Text_Wiki::factory('Mediawiki');
// set some rendering rules
$wiki->setRenderConf('xhtml', 'wikilink', 'view_url', 'http://en.wikipedia.org/wiki/');
$wiki->setRenderConf('xhtml', 'wikilink', 'pages', false);
// define page title
$query = 'The A Team';
try {
// initialize REST client
$wikipedia = new Zend_Rest_Client('http://en.wikipedia.org/w/api.php');
// set query parameters
$wikipedia->action('query');
$wikipedia->prop('revisions');
$wikipedia->rvprop('content');
$wikipedia->format('xml');
$wikipedia->redirects('1');
$wikipedia->titles($query);
// perform request
// get page content as XML
$result = $wikipedia->get();
$content = $result->query->pages->page->revisions->rev;
} catch (Exception $e) {
die('ERROR: ' . $e->getMessage());
}
?>
<html>
<head>
</head>
<body>
<h2>Page result for '<?php