10个不太为人所知的,但实用的PHP函数
10個(gè)不太為人所知的,但實(shí)用的PHP函數(shù)
| 您的評價(jià): | ????? | 較差 | ?收藏該經(jīng)驗(yàn)???? |
閱讀目錄
- php_check_syntax
- highlight_string
- show_source
- php_strip_whitespace
- __halt_compiler
- highlight_file
- ignore_user_abort
- str_word_count
- get_defined_vars
- get_browser
PHP擁有非常豐富的內(nèi)置函數(shù),并且大多數(shù)我們是知道的。有許多功能,這些功能不是很出名,但真的非常有用。在這篇文章中,我已經(jīng)列出并解釋了一些鮮為人知的,但真正有用的PHP函數(shù)。
?
php_check_syntax
這是一個(gè)非常有用的功能,用于檢查一個(gè)指定文件的語法。
用法:
?| 1 2 3 4 5 6 7 8 9 | <?php $error_message =?""; $filename =?"./php_script.php"; if(!php_check_syntax($filename, &$error_message)) { ???echo "Errors were found in the file $filename: $error_message"; }?else { ???echo "The file $filename contained no syntax errors"; } ?> |
來源:?http://www.php.net/manual/en/function.php-check-syntax.php
回到頂部highlight_string
該highlight_string()函數(shù)可以讓我們在Web頁面上展示語法高亮的PHP代碼。這個(gè)函數(shù)利用內(nèi)置的語法高亮功能對給定的PHP代碼進(jìn)行語法著色,并返回結(jié)果。
用法:
?| 1 2 3 | <?php highlight_string(' <?php phpinfo(); ?>'); ?> |
來源:?http://php.net/manual/en/function.highlight-string.php
回到頂部show_source
show_source() 函數(shù)的功能與上面介紹的 highlight_file () 相似。可以對一個(gè)給定的PHP文件進(jìn)行語法著色。語法高亮使用HTML標(biāo)記。運(yùn)行成功返回TRUE,失敗返回FALSE。
用法:
?| 1 2 3 | <?php show_source("php_script.php"); ?> |
來源:?http://www.php.net/manual/en/function.show-source.php
回到頂部php_strip_whitespace
如前所述,與show_source()函數(shù)類似。此函數(shù)也是返回特定文件源代碼。但是刪除了PHP注釋和空白的源代碼。
用法:
?| 1 2 3 | <?php echo php_strip_whitespace("php_script.php"); ?> |
來源:?http://www.php.net/manual/en/function.php-strip-whitespace.php
回到頂部__halt_compiler
此函數(shù)用于停止編譯器的執(zhí)行。這對于在PHP腳本中嵌入數(shù)據(jù)很有用,如安裝文件。
用法:
?| 1 2 3 4 5 6 7 | <?php $fp =?fopen(__FILE__,?'r'); fseek($fp, __COMPILER_HALT_OFFSET__); var_dump(stream_get_contents($fp)); // the end of the script execution __halt_compiler(); ?> |
來源:?http://www.php.net/manual/en/function.halt-compiler.php
回到頂部highlight_file
這是一個(gè)非常的PHP函數(shù)返回帶PHP語法高亮顯示特定PHP文件。
用法:
?| 1 2 3 | <?php highlight_file("php_script.php"); ?> |
來源:?http://www.php.net/manual/en/function.highlight-file.php
回到頂部ignore_user_abort
此功能可用于客戶端ABOT腳本。客戶端將中止導(dǎo)致腳本停止運(yùn)行。
用法 ?| 1 2 3 | <?php ignore_user_abort(); ?> |
來源:?http://www.php.net/manual/en/function.ignore-user-abort.php
回到頂部str_word_count
這個(gè)函數(shù)是用來計(jì)算在字符串中找到詞的數(shù)量。
用法:
?| 1 2 3 | <?php echo str_word_count("Hello How Are You!"); ?> |
來源:?http://php.net/manual/en/function.str-word-count.php
回到頂部get_defined_vars
這是一個(gè)方便的功能,調(diào)試時(shí)。該函數(shù)能夠返回一個(gè)包含所有定義的變量列表的多維數(shù)組。
用法:
?| 1 2 3 | <?php print_r(get_defined_vars()); ?> |
來源:?http://php.net/manual/en/function.get-defined-vars.php
回到頂部get_browser
?這個(gè)函數(shù)會查找查找browscap.ini文件并返回瀏覽器的性能。
用法:
?| 1 2 3 4 5 | <?php echo $_SERVER['HTTP_USER_AGENT']; $browser = get_browser(); print_r($browser); ?> |
來源:?http://www.php.net/manual/en/function.get-browser.php
總結(jié)
以上是生活随笔為你收集整理的10个不太为人所知的,但实用的PHP函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用docker部署一个直接可用的pup
- 下一篇: ASP.NET内置对象一