當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Zend_Rest_Client::exintro方法代碼示例

本文整理匯總了PHP中Zend_Rest_Client::exintro方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Rest_Client::exintro方法的具體用法?PHP Zend_Rest_Client::exintro怎麽用?PHP Zend_Rest_Client::exintro使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend_Rest_Client的用法示例。


在下文中一共展示了Zend_Rest_Client::exintro方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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());
     }
 }
開發者ID:Makae,項目名稱:ch.bfh.bti7054.w2014.q.groot,代碼行數:79,代碼來源:class.utilities.php


注:本文中的Zend_Rest_Client::exintro方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。