網路上許多所謂「PHP 函數大全」其實並不完整。本文整理 PHP 5 核心函數,按功能分類,方便開發者快速查找。
sleep()、usleep()、time_nanosleep()、time_sleep_until():延遲執行ignore_user_abort():用戶斷線是否終止腳本exit()、die():輸出訊息並結束腳本eval():執行字串作為 PHP 代碼highlight_file()、highlight_string()、show_source():語法高亮顯示strip_whitespace():移除註解與空白get_browser():取得瀏覽器能力資訊connection_status()、connection_aborted():連線狀態檢查define()、defined()、constant()zip_open()、zip_read()、zip_close()zip_entry_open()、zip_entry_read()、zip_entry_name()、zip_entry_filesize()、zip_entry_compressedsize()、zip_entry_compressionmethod()、zip_entry_close()xml_parser_create()、xml_parser_create_ns()、xml_parser_free()xml_parse()、xml_parse_into_struct()xml_set_element_handler()、xml_set_character_data_handler()、xml_set_default_handler() 等xml_get_error_code()、xml_error_string()、xml_get_current_line_number() 等| 分類 | 函數 |
|---|---|
| 大小寫轉換 | strtolower()、strtoupper()、ucfirst()、ucwords() |
| 修剪與填充 | trim()、ltrim()、rtrim()、str_pad() |
| 查找與替換 | strpos()、strrpos()、stripos()、strripos()、strstr()、stristr()、str_replace()、str_ireplace()、substr_replace() |
| 截取與分割 | substr()、substr_count()、substr_compare()、explode()、implode()、str_split()、strtok() |
| 比較 | strcmp()、strcasecmp()、strncmp()、strnatcmp()、strnatcasecmp() |
| 編碼與雜湊 | md5()、md5_file()、sha1()、sha1_file()、crypt()、base64_encode()、base64_decode()、urlencode()、urldecode() |
| 格式化 | sprintf()、printf()、vsprintf()、vprintf()、number_format()、money_format() |
| 其他 | strlen()、strrev()、str_shuffle()、str_rot13()、wordwrap()、nl2br()、strip_tags()、addslashes()、stripslashes()、htmlspecialchars()、htmlentities() |
array()、range()、array_fill()array_keys()、array_values()、array_flip()、array_reverse()array_push()、array_pop()、array_unshift()、array_shift()array_merge()、array_diff()、array_intersect()in_array()、array_search()、array_filter()、array_map()sort()、rsort()、asort()、arsort()、ksort()、krsort()、usort()count()、sizeof()、array_unique()、array_chunk()、array_slice()、array_splice()、extract()、compact()date()、time()、mktime()、strtotime()、date_default_timezone_set()、DateTime 類別fopen()、fclose()、fread()、fwrite()、file_get_contents()、file_put_contents()、file()、copy()、unlink()、mkdir()、rmdir()、is_readable()、is_writable()、filesize()、filemtime()更多函數請參考 PHP 官方函數參考。