#!/usr/bin/php under the GPL: http://www.gnu.org/licenses/gpl.txt * * Updated: * 2005-08-31: added html_decode() at final print statement * 2006-08-12: changes for more consistent functionality by Jeff Gould jrgould (at) gmail (dot) com **/ require_once 'lib.php'; # http://dev.expocom.nl/functions.php?id=61 /*if ($argc == 1) { echo " pdoc fetches the first few lines of syntax for given functions from nl.php.net (in English)\n". " Usage: pdoc {function}\n"; return; }*/ # Settings ini_set('display_errors', '1'); ini_set('track_errors', '1'); $func = $argv[1]; if($func == 'snipex'){ $tab = true; $func = $argv[2]; } ob_start(); $func = preg_replace('/[\(\) ;]/','', $func); $function = str_replace('_', '-', $func).'.php'; $url = 'http://us2.php.net/manual/en/function.'; $header = "Accept-Language: en-gb, en"; $options = array('CURLOPT_HTTPHEADER' => array($header)); $res = fetch_url($url . $function, $options); if ($res[0] != 200) { if ($res == 302) { echo "Function not found"; }else{ //echo "Error fetching syntax, ". $res[1]; print $func; } //echo "\n"; //return false; }else{ if (strtolower($argv[2])=='w') { //echo "Opening $url$function.. \n"; shell_exec('open '. $url.$function); //die(); } $data = $res[1]; } $start = 'Swedish'; # nice point to start cutting if($data){ $data = substr($data, strpos($data, $start) + strlen($start), 1000); # cuts underneath the table with 'last updated' and stuff $data = substr($data, strpos(strtolower($data), '') + 8); # replace linebreaks with spaces, fix tags, remove nonbreaking spaces $data = str_replace(array(' ', "\n", ' >'), array(' ', ' ', '>'), nl2unix($data)); # insert linebreaks for paragraph and header tags $data = str_replace(array('

', '

'), "\n", $data); $data = str_replace(array('

', '

'), "\n", $data); # cut until the first ')' after the description identifier (that's '

') $find = strpos(strtolower($data), '

'); $find = strpos(strtolower($data), ')', $find + 5); $data = substr($data, 0, $find + 1); # then insert linebreaks for

too $data = str_replace(array('

', '

'), "\n", $data); # remove all the tags and remove double returns $data = strip_tags($data); $data = trim(str_replace("\n\n", "\n", $data)); $data = explode("\n", $data); if(!$tab){ $data = $data[2]."\n".$data[4]; print html_decode($data); # from lib.php //echo "\n\n"; }else{ $data = $data[4]; $data = html_decode(substr($data, strpos($data, ' ')+1, strlen($data))); print rtrim(ltrim(preg_replace(array('/[\n\r]+/', '/ \(/', ), array('', '$1('),$data))); } } $output = ob_get_contents(); ob_end_clean(); if( (strlen($output)>strlen($func)) && (strlen($output)<1000)) print $output; else{ if(!$tab) print "error: function not found [ $func()]"; else print $func.'()'; } ?>