「文字列を与えたら、日付に直してくれる関数」をさがしていた。見ていくのがだるい。それっぽい名前を見つけて、詳細を閲覧、違うとまたさがして詳細を閲覧。コレの繰り返し。いらついた。
すごくむかつきませんか。PHPのマニュアルが。詳しいのは分かるのだけど面倒。Javaのように、「引数&戻り値一覧」を記載してほしい。
腹が立ったので、Web::Scraperでぱぱっと取ってきた。返り値で並び替えたので見やすくなった。
PHP日付関数の引数と戻り値一覧。
<?php DateInterval::__construct ( string $interval_spec ) DatePeriod::__construct ( DateTime $start , DateInterval $interval , int $recurrences [, int $options ] ) DateTime date_create ([ string $time="now" [, DateTimeZone $timezone=NULL ]] ) DateTime::__construct ([ string $time="now" [, DateTimeZone $timezone=NULL ]] ) DateTimeZone timezone_open ( string $timezone ) DateTimeZone::__construct ( string $timezone ) __construct ( DateTime $start , DateInterval $interval , int $recurrences [, int $options ] ) __construct ( string $interval_spec ) __construct ( string $timezone ) array DateTimeZone::getTransitions ([ int $timestamp_begin [, int $timestamp_end ]] ) array DateTimeZone::listAbbreviations ( void ) array DateTimeZone::listIdentifiers ([ int $what=DateTime::ALL [, string $country=NULL ]] ) array date_parse ( string $date ) array date_parse_from_format ( string $format , string $date ) array date_sun_info ( int $time , float $latitude , float $longitude ) array getdate ([ int $timestamp=time() ] ) array localtime ([ int $timestamp=time() [, bool $is_associative=false ]] ) array strptime ( string $date , string $format ) bool checkdate ( int $month , int $day , int $year ) bool date_default_timezone_set ( string $timezone_identifier ) int DateTimeZone::getOffset ( DateTime $datetime ) int gmmktime ([ int $hour=gmdate("H") [, int $minute=gmdate("i") [, int $second=gmdate("s") [, int $month=gmdate("n") [, int $day=gmdate("j") [, int $year=gmdate("Y") [, int $is_dst=-1 ]]]]]]] ) int idate ( string $format [, int $timestamp=time() ] ) int mktime ([ int $hour=date("H") [, int $minute=date("i") [, int $second=date("s") [, int $month=date("n") [, int $day=date("j") [, int $year=date("Y") [, int $is_dst=-1 ]]]]]]] ) int strtotime ( string $time [, int $now ] ) int time ( void ) mixed date_sunrise ( int $timestamp [, int $format=SUNFUNCS_RET_STRING [, float $latitude=ini_get("date.default_latitude") [, float $longitude=ini_get("date.default_longitude") [, float $zenith=ini_get("date.sunrise_zenith") [, float $gmt_offset=0 ]]]]] ) mixed date_sunset ( int $timestamp [, int $format=SUNFUNCS_RET_STRING [, float $latitude=ini_get("date.default_latitude") [, float $longitude=ini_get("date.default_longitude") [, float $zenith=ini_get("date.sunset_zenith") [, float $gmt_offset=0 ]]]]] ) mixed gettimeofday ([ bool $return_float ] ) mixed microtime ([ bool $get_as_float ] ) public DateInterval DateTime::diff ( DateTime $datetime [, bool $absolute ] ) public DateTime DateTime::__wakeup ( void ) public DateTime DateTime::add ( string $interval ) public DateTime DateTime::modify ( string $modify ) public DateTime DateTime::setDate ( int $year , int $month , int $day ) public DateTime DateTime::setISODate ( int $year , int $week [, int $day ] ) public DateTime DateTime::setTime ( int $hour , int $minute [, int $second ] ) public DateTime DateTime::setTimestamp ( int $unixtimestamp ) public DateTime DateTime::setTimezone ( DateTimeZone $timezone ) public DateTime DateTime::sub ( DateInterval $interval ) public DateTime add ( string $interval ) public DateTimeZone DateTime::getTimezone ( void ) public array DateTimeZone::getLocation ( void ) public int DateTime::getOffset ( void ) public int DateTime::getTimestamp ( void ) public static DateInterval DateInterval::createFromDateString ( string $time ) public static DateTime DateTime::__set_state ( array $array ) public static DateTime DateTime::createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] ) public static array DateTime::getLastErrors ( void ) public string DateInterval::format ( void ) public string DateTime::format ( string $format ) public string DateTimeZone::getName ( void ) string date ( string $format [, int $timestamp ] ) string date_default_timezone_get ( void ) string gmdate ( string $format [, int $timestamp ] ) string gmstrftime ( string $format [, int $timestamp=time() ] ) string strftime ( string $format [, int $timestamp ] ) string timezone_name_from_abbr ( string $abbr [, int $gmtOffset=-1 [, int $isdst=-1 ]] )
文字列関数
ついでに文字列関数も、いつも探し回るので、作っておいた。
<?php array explode ( string $delimiter , string $string [, int $limit=-1 ] ) array get_html_translation_table ([ int $table=HTML_SPECIALCHARS [, int $quote_style=ENT_COMPAT ]] ) array localeconv ( void ) array str_getcsv ( string $input [, string $delimiter [, string $enclosure [, string $escape ]]] ) array str_split ( string $string [, int $split_length=1 ] ) int crc32 ( string $str ) int fprintf ( resource $handle , string $format [, mixed $args [, mixed $... ]] ) int levenshtein ( string $str1 , string $str2 ) int ord ( string $string ) int print ( string $arg ) int printf ( string $format [, mixed $args [, mixed $... ]] ) int similar_text ( string $first , string $second [, float &$percent ] ) int strcasecmp ( string $str1 , string $str2 ) int strcmp ( string $str1 , string $str2 ) int strcoll ( string $str1 , string $str2 ) int strcspn ( string $str1 , string $str2 [, int $start [, int $length ]] ) int stripos ( string $haystack , string $needle [, int $offset=0 ] ) int strlen ( string $string ) int strnatcasecmp ( string $str1 , string $str2 ) int strnatcmp ( string $str1 , string $str2 ) int strncasecmp ( string $str1 , string $str2 , int $len ) int strncmp ( string $str1 , string $str2 , int $len ) int strpos ( string $haystack , mixed $needle [, int $offset=0 ] ) int strripos ( string $haystack , string $needle [, int $offset=0 ] ) int strrpos ( string $haystack , string $needle [, int $offset=0 ] ) int strspn ( string $str1 , string $str2 [, int $start [, int $length ]] ) int substr_compare ( string $main_str , string $str , int $offset [, int $length=0 [, bool $case_insensitivity=false ]] ) int substr_count ( string $haystack , string $needle [, int $offset=0 [, int $length ]] ) int vfprintf ( resource $handle , string $format , array $args ) int vprintf ( string $format , array $args ) mixed count_chars ( string $string [, int $mode=0 ] ) mixed sscanf ( string $str , string $format [, mixed &$... ] ) mixed str_ireplace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) mixed str_word_count ( string $string [, int $format=0 [, string $charlist ]] ) mixed substr_replace ( mixed $string , string $replacement , int $start [, int $length ] ) string addcslashes ( string $str , string $charlist ) string addslashes ( string $str ) string bin2hex ( string $str ) string chr ( int $ascii ) string chunk_split ( string $body [, int $chunklen [, string $end ]] ) string convert_cyr_string ( string $str , string $from , string $to ) string convert_uudecode ( string $data ) string convert_uuencode ( string $data ) string crypt ( string $str [, string $salt ] ) string hebrev ( string $hebrew_text [, int $max_chars_per_line=0 ] ) string hebrevc ( string $hebrew_text [, int $max_chars_per_line=0 ] ) string html_entity_decode ( string $string [, int $quote_style=ENT_COMPAT [, string $charset ]] ) string htmlentities ( string $string [, int $quote_style=ENT_COMPAT [, string $charset [, bool $double_encode=true ]]] ) string htmlspecialchars ( string $string [, int $quote_style=ENT_COMPAT [, string $charset [, bool $double_encode=true ]]] ) string htmlspecialchars_decode ( string $string [, int $quote_style=ENT_COMPAT ] ) string implode ( string $glue , array $pieces ) string lcfirst ( string $str ) string ltrim ( string $str [, string $charlist ] ) string md5 ( string $str [, bool $raw_output=false ] ) string md5_file ( string $filename [, bool $raw_output=false ] ) string metaphone ( string $str [, int $phones=0 ] ) string money_format ( string $format , float $number ) string nl2br ( string $string [, bool $is_xhtml=true ] ) string nl_langinfo ( int $item ) string number_format ( float $number [, int $decimals ] ) string quoted_printable_decode ( string $str ) string quoted_printable_encode ( string $str ) string quotemeta ( string $str ) string rtrim ( string $str [, string $charlist ] ) string setlocale ( int $category , string $locale [, string $... ] ) string sha1 ( string $str [, bool $raw_output=false ] ) string sha1_file ( string $filename [, bool $raw_output=false ] ) string soundex ( string $str ) string sprintf ( string $format [, mixed $args [, mixed $... ]] ) string str_pad ( string $input , int $pad_length [, string $pad_string=" " [, int $pad_type=STR_PAD_RIGHT ]] ) string str_repeat ( string $input , int $multiplier ) string str_rot13 ( string $str ) string str_shuffle ( string $str ) string strip_tags ( string $str [, string $allowable_tags ] ) string stripcslashes ( string $str ) string stripslashes ( string $str ) string stristr ( string $haystack , mixed $needle [, bool $before_needle=false ] ) string strpbrk ( string $haystack , string $char_list ) string strrchr ( string $haystack , mixed $needle ) string strrev ( string $string ) string strstr ( string $haystack , mixed $needle [, bool $before_needle=false ] ) string strtok ( string $str , string $token ) string strtolower ( string $str ) string strtoupper ( string $string ) string strtr ( string $str , string $from , string $to ) string substr ( string $string , int $start [, int $length ] ) string trim ( string $str [, string $charlist ] ) string ucfirst ( string $str ) string ucwords ( string $str ) string vsprintf ( string $format , array $args ) string wordwrap ( string $str [, int $width=75 [, string $break="\n" [, bool $cut=false ]]] ) void echo ( string $arg1 [, string $... ] ) void parse_str ( string $str [, array &$arr ] )
ちなみにWeb::Scraperのコードはコレ
Perlって楽しいね。PHP書くのは結構苦痛。Web::Scraperとか超便利です。
URL指定すると、そのページにある関数一覧を作って、引数と戻り値の一覧にして返却します。
あとはコマンドでソートする
$ perl ListPHPFuncs.pl | sort > func.list.txt
ListPHPFuncs.pl
#!/usr/bin/perl use strict; use Web::Scraper; use URI; use YAML; my $uri = URI->new(shift || "http://jp2.php.net/datetime"); my $scraper = scraper { process 'ul.chunklist li a', 'links[]' => sub{ $_->attr('href'); }; return 'links'; }; my $result = $scraper->scrape($uri); #print Dump $result->{links}; my @urls; for my $a ( @{$result->{links}} ){ push(@urls, "http://jp2.php.net/manual/ja/".$a); } undef $result; undef $scraper; for my $i (@urls){ print STDERR " \r"; print STDERR $i."\r"; print synopsis($i); print "\n"; } sub synopsis{ my $uri = URI->new(shift || "http://jp2.php.net/manual/ja/datetime.sub.php"); my $_scraper = scraper { process '//div[contains(@class, "dc-description")]', 'synopsis'=> 'text'; result 'synopsis'; }; my $_result = $_scraper->scrape($uri); #print Data::Dumper $_result; return $_result; }