The wiki's API format://language abbreviation. wikipedia.org/w/api.php?&action=query&titles= language corresponding to the text &format= return format &prop= Revisions&rvprop=content
I'm now doing a Chinese history today get XML data (prop for version specific parameters click on the Chinese API and document view)
The requested URL is: Http://zh.wikipedia.org/w/api.php?action=query&titles=12 month 31st &format=xml&prop=revisions &rvprop=content
$str = file_get_contents ($need _url);//$content = $result->query->pages->page->revisions->rev; $obj = Simplexml_load_string ($str, ' simplexmlelement ', libxml_nocdata); $obj =get_object_vars ($obj); $revisions = $obj [' Query ']->pages->page->revisions->rev;
Print $revisions found that the data is a wiki tag, we need to do is to remove the wiki tag, Baidu found PEAR Text_wiki package, it can be implemented in wikitext and many other formats to convert each other.
So the first thing to do is to install pear
To modify the configuration file php.ini:
include_path = "D:\wnmp\php5\PEAR\"
Install Pear:
All the way up there. If not, please enter all when selecting all to fill in the system or local time to fill in the local basic can go all the way down
If you encounter
Channel "Pear.php.net" has updated it protocols, use ' pear channel-update pear.php.net ' to update
This error is a version issue just perform the following:
The above is excerpt someone else's back will give the link
Pear remote-list command is a list of all the pear packages because the package compares more to execute this command the corresponding event is slightly longer
Here are the two wiki packs we need to install.
Installation
Install the second time error, at the beginning did not read the wrong thought is the pear version of the problem later only to know that a given Mediawiki version execution: Pear Install text_wiki_mediawiki-0.2.0 can
All right, the Wiki conversion package is installed successfully!
Call the Wiki transformation package:
Find the newly installed Wiki conversion package My installation path is: D:\wnmp\php5\PEAR\pear\Text
Copy the text file to the PHP working directory and include the wiki.php in the PHP file
Require_once './text/wiki.php ';//Instantiate a Text_wiki object from the given class//and set it to use the Mediawiki ad Apter$wiki = & Text_wiki::factory (' Mediawiki ');//Set some rendering rules $wiki->setrenderconf (' xhtml ', ' Wikilink ', ' view_url ', ' http://zh.wikipedia.org/wiki/'); $wiki->setrenderconf (' xhtml ', ' wikilink ', ' pages ', false echo $wiki->transform ($revisions, ' Xhtml ');
After viewing the webpage a little garbled;
Wikiapi Invoke Tutorial: http://www.ibm.com/developerworks/cn/xml/x-phpwikipedia/This tutorial is used by the ZF framework to invoke zend_rest_ on the basis of the ZF framework Client Class
Pear Error: http://blog.csdn.net/chensong0708/article/details/6634848
There are a lot of pear installed tutorial Baidu A lot of will not say
Simple invocation of the Wikipedia API and the escape of Wiki tags (installation and use of pear)