ȥå   Խ ʬ Хåå ź ʣ ̾ѹ   ñ측 ǽ   إ   ǽRSS

PHP/API ѹ

Top / PHP / API

[[PHP]]

#contents

*̹
**Υå
|is_string($var)|stringĴ٤ޤ|
|is_int($var)|integerĴ٤ޤ|
|is_float($var)|floatĴ٤ޤ|
|is_bool($var)|booleanĴ٤ޤ|
|is_array($var)|Ĵ٤ޤ|
|is_resource($var)|꥽Ĵ٤ޤ|
|is_object($var)|֥ȤĴ٤ޤ|
|is_scalar($var)|ͤʸbooleanʳĴ٤ޤ|
|is_numeric($var)|ͤʸ󤫡ʳĴ٤ޤ|
|is_null($var)|nullĴ٤ޤ|
|isset($var)|ѿͤꤵƤ뤫Ĵ٤ޤ|
|is_null($var)|ѿͤNULLĴ٤ޤ¸ߤʤѿФƻȤTRUE֤ޤ⤽ȤʤǤʷٹ𤬽Фޤˡ|
|isset($var)|ѿ¸ߤNULLʳͤꤵƤ뤫Ĵ٤ޤGETPOSTͤäƤ뤫Ĵ٤Ȥ˻Ѥޤ|

**Ѵ
|intval("123")|10ʿʸ  |
|intval("1110", 2)|ʿʸ  |
|intval("777", 8)|ʿʸ  |
|intval("fff0", 16)|16ʿʸ  |

ʸͤȤưȤƬϤޤͤͤȤʤޤѻϤޤȤϣȤʤޤ
 echo 2+'30degree';  32

*
:print "Hello!";|ʸϤޤ칽¤ʤΤdz̤ǤʤƤ⵭ҤǤޤ
:echo "Hello!";|ʸϤޤ칽¤ʤΤdz̤ǤʤƤ⵭ҤǤޤ
:print_r();|ƤϤޤ
:var_dump();|ηƤϤޤ
:var_export();|PHPƤϤޤ



*ʸ
:chr()|ɤʸѴޤ
:ord(ʸ)|ƬʸΥɤ֤ޤ



*ʸ
**
:$str1 . $str2|ʸϢԤޤ
:strlen($str)|ʸΥХȿ֤ޤ
:mb_strlen($str(, "SJIS"))|ʸʸ֤ޤ
:strcmp($str1, $str2)|Ӥ$str1Ȥ֤ͤޤ
:strcmp($str1, $str2, ӥХȥ)|ꤷХȿӤ$str1Ȥ֤ͤޤ
:strcasecmp($str1, $str2)|ʸʸ̤˼Ӥ$str1Ȥ֤ͤޤ
:str_repeat($str, ֤)|ʸ¤٤ʸ֤ޤ
:str_pad($str, Хȿ, "=", STR_PAD_BOTH)|ХȿĹˤʤޤǡξü᤿ʸ֤ޤSTR_PAD_LEFT, STR_PAD_RIGHTǤޤ

**Ф
:substr($str, ϥХȰ, ФХȿ)|ꤷХȰ֤ĹʸФޤϥХȿޥʥΤȤХܤ鳫ϤޤФХȿޥʥΤȤƤΥХܤ꺸¦ޤǤФޤ
:substr($str, ϥХȰ)|ꤷХȰ֤ޤǤʸФޤ
:mb_substr($str, ʸ, Фʸ)|ʸ󥳡ǥ󥰤ˡꤷʸ֤ĹʸФޤ
:mb_substr($str, ʸ, Фʸ, "SJIS")|ꤷ󥳡ǥ󥰤ˡꤷʸ֤ĹʸФޤ
:strstr($str, $strSearchWord)|ǽ˸Ĥäʸ󤫤ޤǤʸФޤĤʤFALSE֤ޤ
:stristr($str, $strSearchWord)|ʸʸ̤˺ǽ˸Ĥäʸ󤫤ޤǤʸФޤĤʤFALSE֤ޤ
:strchr($str, ʸ)|Ǹ˸ĤäʸޤǤʸʸޤ֤ޤsubstr(strchr($str, ʸ), 1)ȤСޤ᤺˼Ǥޤ
:list($strNumber, $strExt) = sscanf("img15.gif", "img%d.%s");|ʸ󤫤եޥåȤ˽äưФޤ
:sscanf("img15.gif", "img%d.%s", &$strNumber, &$strExt);|ʸ󤫤եޥåȤ˽äưФޤ

աPHPǤʸ"0"פFALSEȤʤΤǡ"0"פ򸡺ȤդɬפǤ

**
:strpos($str, $strSearchWord)|ǽ˸ĤäХȰ֤֤ޤĤʤȤFALSE֤ޤ
:strpos($str, $strSearchWord, ϥХȰ)|ꤷХȰ֤鸡ǽ˸ĤäХȰ֤֤ޤĤʤȤFALSE֤ޤ
:strrpos($str, $strSearchWord)|Ǹ˸ĤäХȰ֤֤ޤĤʤȤFALSE֤ޤ
:mb_strpos($str, $strSearchWord)|ǽ˸Ĥäʸ֤֤ޤĤʤȤFALSE֤ޤ
:mb_strpos($str, $strSearchWord, ʸ(, "SJIS"))|ꤷʸ֤鸡ǽ˸Ĥäʸ֤֤ޤ
:mb_strrpos($str, $strSearchWord(, "SJIS"))|Ǹ˸ĤäХȰ֤֤ޤĤʤȤFALSE֤ޤ
:substr_count($str, ʸ)|ʸνи֤ޤ

աPHPǤϿ0FALSEȤʤΤդɬפǤ

**ִ
:substr_replace($str, ִʸ, ϥХȰ, Хȿ)|ʸΰ֤ޤ
:substr_replace($str, ִʸ, ϥХȰ)|ʸ֤ޤ
:str_replace(ִʸ, ִʸ, $str)|Ĥä٤Ƥʸ̤ʸ֤ޤ
:strtr($str, ִʸå, ִʸå)|ʸåȤ˴ޤޤʸ򤽤줾ִޤ
:strtr($str, Ϣ)|ϢΥʸʸִޤ
:strrev($str)|ʸդޤˤޤ
:mb_convert_kana($str, ܸѴץʸ(, ʸ))|ѡȾѴԤޤ
|r|ѱѻ  Ⱦѱѻ|
|R|Ⱦѱѻ  ѱѻ|
|n|ѿ  Ⱦѿ|
|N|Ⱦѿ  ѿ|
|a|ѱѿ  Ⱦѱѿ|
|A|Ⱦѱѿ  ѱѿ|
|s|ѥڡ  Ⱦѥڡ|
|S|Ⱦѥڡ  ѥڡ|
|k|ѥ  Ⱦѥ|
|K|Ⱦѥ  ѥʡʸ|
|KV|Ⱦѥ  ѥʡϵͤ|
|h|ѤҤ餬  ȾѤҤ餬|
|H|ȾѤҤ餬  ѤҤ餬ʡʸ|
|HV|ȾѤҤ餬  ѤҤ餬ʡϵͤ|
|c|ѥ  ѤҤ餬|
|C|ѤҤ餬  ѥ|

**
:$str = sprintf("%02d", $i);|եޥåȤʸ֤ޤ
:number_format($strNumber)|ʸ򣳷Υ޶ڤ֤ޤ
:trim($str)|ζޤ
:ltrim($str)|¦ζޤ
:rtrim($str)|¦ζޤ
:wordwrap($str, 10, "<br>", 1)|ХȿDzԤޤ裳ꤵƤʤȤϲʸȤʤޤ˻ʸǽȤϺǸΥѥ᡼ˣꤷޤȾѤѤߤƤȤ˽Ǥʤ礬ޤ

**ʸѴ
ǽʸɰ
|EUC-JP|ܸUNIXƥɸʸ|
|SJIS|Windows, Macɸʸ|
|UTF-8|Unicode|
|JIS|Żҥ᡼ʤɤǻȤʸ|

:mb_detect_encoding($str)|ʸϤʸʸޤ
:mb_internal_encoding()|ʸɤɽʸޤ
:mb_internal_encoding("UTF-8")|ʸɤUTF-8ꤷޤ¾"SJIS", "JIS", "EUC-JP"Ǥޤ
:mb_convert_encoding($str, "UTF-8")|ʸɤUTF-8ؤʸѴԤޤ
:mb_convert_encoding($str, "UTF-8", "SJIS")|SJISʸɤUTF-8ؤʸѴԤޤ
:mb_convert_variables("UTF-8", "SJIS", $arList)|󤹤٤ƤǤǡSJISUTF-8ؤʸѴԤޤ

**webϤѴ
:nl2br($str)|ʸ<br />Ѵޤ
:htmlspecialchars($str)|HTMLʸ&lt;&gt;&#039;&amp;&quot;פ&amp;lt;פʤɤѴޤ
:strip_tags($str)|HTMLޤ
:addslashes($str)|󥰥륯('), ֥륯("),Хåå (\) ,NUL (̥Х)  \ ǥפޤDB˥ǡǼˡ¹ԤƤޤեJISɤΣХܤХååξ⥨פΤդƤ
:stripslashes($str)|פ줿󥰥륯('), ֥륯("),Хåå (\) ,NUL (̥Х) Υ׵ \ ޤDBǡȤ˼¹Ԥޤ
:urlencode(󥳡ʸ)|URL󥳡ɤʸ֤ޤ
:urldecode(󥳡ɸʸ)|URLǥɤʸ֤ޤ
:parse_str("p1=a&p2=b")|ʸϤơѿξ$p1, $p2)ޤ

**¾Ѵ
:strtolower($str)|ʸִޤ
:strtoupper($str)|ʸִޤ
:dechex(255)|10ʿ  16ʿɽʸ֤ޤξ"ff"֤ޤ
:hexdec("ff")|16ʿ  10ʿɽʸ֤ޤξ"255"֤ޤ
:decbin(12)|10ʿ  2ʿɽʸ֤ޤξ"1100"֤ޤ
:bindec("1100")|2ʿ  10ʿɽʸ֤ޤξ"12"֤ޤ
:base_convert("oldʿʸ", oldʿ, newʿ)|oldʿʸ󤫤newʿʸѴޤ
:crypt($str(, ŹΥ١Ȥʤ룲ʸ))|DES르ꥺѴϥåʸ֤ޤ
:md5($str)|MD5르ꥺѴϥåʸ֤ޤ
:sha1($str)|sha1르ꥺѴϥåʸ֤ޤ
:crc32($str)|CRCå֤ͤޤ
:uniqid()|13ʸΥˡIDʸޤ
:escapleshellcmd($str)|Υ᥿ʸ򥨥



*ͱ黻
**
:round($f)|裱̤ǻͼθޤ
:floor($f)|裱̤ڤΤƤޤ
:ceil($f)|裱̤ڤ夲ޤ
:abs($f)|ͤޤ
:pow($i, $n)|$i$nͤޤ
:sqrt($f)|ʿޤ
:max($a, $b(, ...))|֤ͤޤ
:max()|֤ͤޤ
:min($a, $b(, ...))|Ǿ֤ͤޤ
:min()|Ǿ֤ͤޤ
:rand(Ǿ, )|ǾͰʾ塢ְʲ֤ޤsrand((double)microtime() * 100000);
:mt_rand(Ǿ, )|ǾͰʾ塢ְʲ®֤ޤmt_srand((double)microtime() * 100000);

**
:deg2rad(30)|ñ̤γ  饸ñ̤γ
:rad2deg(2 * M_PI / 8)|饸ñ̤γ  ñ̤γ
:sin(deg2rad(30))|ͤޤ
:cos(deg2rad(30))|ͤޤ
:tan(deg2rad(30))|󥸥ͤޤ
:asin(0.5)|͡ʥ饸ñ̡ˤޤ-1ʾ壱ʲͤꤷޤ
:acos(0.5)|͡ʥ饸ñ̡ˤޤ-1ʾ壱ʲͤꤷޤ
:atan(0.5)|󥸥͡ʥ饸ñ̡ˤޤ
:atan2(x, y)|xyͤꤷơ󥸥͡ʥ饸ñ̡ˤޤ



*
**
:==|ƤƱȤTRUE֤ޤ
:===|ޤƤפȤTRUE֤ޤ
:count($arList)|ǿ֤ޤ
:count($arList, COUNT_RECURSIVE)|¿ǿ֤ޤ
:array_count_values($arList)|ͤ򥭡ȤиͤȤޤ
:end($arList)|κǸ֤ͤޤ
:array_key_exists($strKey, $arList)|˥¸ߤTRUE֤ޤ
:isset($arList[$strKey])|˥¸ߤNULLʳͤꤵƤTRUE֤ޤ
:in_array(&strValue, $arList)|ͤ¸ߤTRUE֤ޤ
:array_search(&strValue, $arList)|ͤ¸ߤХǥå֤ޤ¸ߤʤFALSE֤ޤաPHPǤϿ0FALSEȤʤΤդɬפǤ
:array_sum($arList)|ͤιͤ׻֤ޤ
:array_walk($arList, "func_name")|function func_name($value, $key){...}˳ǤƸƤӽФޤ

**ɲá
:array_push($arList, $item)|   Ǥɲäޤ
:array_pop($arList)|   ǤФޤ
:array_unshift($arList, $item)|   ƬǤɲäޤ
:array_shift($arList)|   ƬǤФޤ
:unset($arList[$key])|λꤷǤޤ
:array_splice($arList, ϥǥå, Ŀ)|ꥤǥåĿǤޤ
:array_splice($arList, ϥǥå, Ŀ, ɲäѿޤ)|ꥤǥåĿǤơɲäޤʤִޤ

**¤ؤ
:sort($arList)|ϢۤǤʤͤξǥȤޤ
:rsort($arList)|ϢۤǤʤͤι߽ǥȤޤ
:asort($arList)|ϢͤξǥȤޤ
:arsort($arList)|Ϣͤι߽ǥȤޤ
:ksort($arList)|Ϣ򥭡ξǥȤޤ
:krsort($arList)|Ϣ򥭡ι߽ǥȤޤ
:natsort($arList)|ǥȤޤ
:array_reverse($arList)|ս¤ؤޤǥåϣޤ
:array_reverse($arList, TRUE)|ս¤ؤޤǥåݻޤ
:array_flip($arList)|ͤؤޤƱͤʣäȤϡǸΥͤȤƻĤޤ
:shuffle($arList)|򥷥åե뤷ޤ餫srand((double)microtime() * 100000);ȽƤޤ

**
:array_keys($arList)|Фơޤ
:array_values($arList)|ͤФơޤ
:array_unique($arList)|󤫤ʣͤޤΤȤĤΤϺǽ˸ĤäȤʤޤ
:array_slice($arList, ϥǥå(, ǿ))|ΰȼФޤǥåϣ鿶ľޤ
:$random_key = array_rand($arList)|Ĥǵޤͤ$arList[$random_key]
:$random_keys = array_rand($arList, Ŀ)|ʣǵޤͤ$arList[$random_keys[0]], $arList[$random_keys[1]], ...

**Ÿ
:list($var1, $var2, $var3, ...) = $arList;|ͤʣѿŸޤ
:extract($arList)|̾ȤѿͤŸޤ
:compact("key1", "key2", "key3", ...)|ѿ̾򥭡ȤƤͤȤϢޤ
:range(, λ(, ֳ))|ͤ齪λͤޤǤͤޤǥåϣȤʤޤ

**ƱΤα黻
:array_merge(Array("a", "b", "c"), Array("b", "x", "y"))|Ƥ礷ޤǥåϣ鿶ľޤξ硢Array(0=>"a", 1=>"b", 2=>"c", 3=>"b", 4=>"x", 5=>"y")Ȥʤޤ
:array_diff(Array("a", "b", "c"), Array("b", "x", "y")(, ...))|ܤ󤫤飲ܰʹߤͤĹܤޤǥåͤϵͤޤξ硢Array(0=>"a", 2=>"c")Ȥʤޤ
:array_diff_assoc(Array("a", "b", "c"), Array("b", "x", "y")(, ...))|ܤ󤫤飲ܰʹߤΥͤפܤޤǥåͤϵͤޤξ硢Array(0=>"a", 1=>"b", 2=>"c")Ȥʤޤ
:array_intersect(Array("a", "b", "c"), Array("b", "x", "y"))|ĤǶ̤ͤĹܤФޤξ硢Array(1=>"b")Ȥʤޤ
:array_intersect_assoc(Array("a", "b", "c"), Array("b", "x", "y"))|ĤǥޤưפͤĹܤФޤξ硢Array()Ȥʤޤ

**ʸʬ
:explode(",", $str)|ʸꤷڤʸʬ䤷֤ޤ<㡧list($year, $month, $day) = explode('-', '2010-01-01');
:[[preg_split("/[\s,]+/", $str(, ʬ))>http://www.php.net/manual/ja/function.preg-split.php]]|ʸꤷڤʸʬ䤷֤ޤڤʸɽȤޤǿѥ᡼ɲäǤޤ֤Υ᥽åɡsplit(侩), spliti, mb_splitɲäʬǤޤ磲ʬ䤹Ȥϣꤷޤ
:str_split($var)|ʸʸŤĤʬ䤷֤ޤ

**ҤȤĤʸ˷
:implode(ڤʸ, $arList)|γǤڤʸϢ뤷ʸ֤ޤ
:join(ڤʸ, $arList)|implodeƱưǤ



*ɽ
**ɽ
|^|Ƭ|
|$||
|.|ǤդΣʸ|
|[ABC]|ABCɤ줫ʸ|
|[A-Z]|AZΤɤ줫ʸ|
|[^A-Za-z]|ե٥åȰʳΣʸ|
|A*|AΣʾ巫֤|
|A+|AΣʾ巫֤|
|A?|Aޤϣ|
|A{5}|A|
|A{5,}|Aʾ|
|A{5,8}|A󤫤飸|
|(ABC)&#x7c;(XYZ)|ABCȤ¤ӤޤXYZȤ¤|
|\n||
|\r||
|\t||
|\$|$Ȥʸ|
|\\|\Ȥʸ|

**ɽȤ߹碌
|(ABC)+|ABCȤ¤Ӥʾ巫֤|
|[a-z]*|ʸʾη֤|
|\$$|$Ȥʸ|

**
:ereg("[A-Z]{3}", $str)|ޥåȤTRUE֤ޤ
:ereg("[A-Z]{3}", $str, $strResult)|ޥåȤTRUE֤$strResult˥ޥåʸ֤ޤ

֤Υ᥽åɡeregi, mb_ereg, mb_eregi

**ִ
:ereg_replace("[A-Z]{3}", ִʸ, $str)|ޥåʸִʸ֤ޤִʸ\\1ȡܤ˥ޥåʸޤ

֤Υ᥽åɡeregi_replace, mb_ereg_replace, mb_eregi_replace

 $str = "0123(45)6789";
 echo ereg_replace("([0-9]{2,})\(([0-9]{1,4})\)([0-9]{4})", "\\1-\\2-\\3", $str);

**ʬ
split򻲾ȤƤ