Rewrote shell_exec(curl...) to PHP5 cURL function
* Added HISTORY file * Bumped to version 0.2 * Updated README with PHP5 cURL module
This commit is contained in:
parent
0a91559a67
commit
72dae5c75b
6
HISTORY
Normal file
6
HISTORY
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
0.1 - 2014-07-28
|
||||||
|
First release of wie
|
||||||
|
|
||||||
|
0.2 - 2014-07-31
|
||||||
|
Changed 'shell_exec(curl -s $URL)' to PHP5 cURL function
|
||||||
|
Added HISTORY file
|
@ -13,6 +13,9 @@ Or run it with 'php wie.php'. To display the help, type:
|
|||||||
|
|
||||||
./wie.php --help
|
./wie.php --help
|
||||||
|
|
||||||
|
## Requirements ##
|
||||||
|
The script requires PHP5 and the PHP5 cURL module (php5-curl on Debian systems).
|
||||||
|
|
||||||
## Thanks ##
|
## Thanks ##
|
||||||
Many thanks goes to flinga who came up with the idea for this script, please see
|
Many thanks goes to flinga who came up with the idea for this script, please see
|
||||||
the THANKS file for more information.
|
the THANKS file for more information.
|
||||||
|
11
wie.php
11
wie.php
@ -22,7 +22,7 @@ $defaultLang = "en"; // default language
|
|||||||
$progName = $argv[0];
|
$progName = $argv[0];
|
||||||
function usage()
|
function usage()
|
||||||
{
|
{
|
||||||
print "Wikipedia ingress extractor (wie), version 0.1\n";
|
print "Wikipedia ingress extractor (wie), version 0.2\n";
|
||||||
print "Usage: $GLOBALS[progName] [--lang=sv] article\n";
|
print "Usage: $GLOBALS[progName] [--lang=sv] article\n";
|
||||||
print "Default language if none specified is $GLOBALS[defaultLang].\n";
|
print "Default language if none specified is $GLOBALS[defaultLang].\n";
|
||||||
print "Remember to quote the article if there's more than one word,\n";
|
print "Remember to quote the article if there's more than one word,\n";
|
||||||
@ -58,7 +58,14 @@ else
|
|||||||
$article = ucwords($article); // uppercase article
|
$article = ucwords($article); // uppercase article
|
||||||
$article = preg_replace("/\s/", "_" ,$article); // make spaces to underscore
|
$article = preg_replace("/\s/", "_" ,$article); // make spaces to underscore
|
||||||
$url = "http://$lang.wikipedia.org/wiki/$article";
|
$url = "http://$lang.wikipedia.org/wiki/$article";
|
||||||
$data = shell_exec("curl -s $url"); // retrive the page
|
|
||||||
|
// get the wiki page
|
||||||
|
$ch = curl_init("$url");
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
$data = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
preg_match("/\<p\>(.*)\<\/p\>/", $data, $match); // fetch text inside first <p>
|
preg_match("/\<p\>(.*)\<\/p\>/", $data, $match); // fetch text inside first <p>
|
||||||
|
|
||||||
// check is we had a match
|
// check is we had a match
|
||||||
|
Loading…
x
Reference in New Issue
Block a user