php_strip_whitespace

(PHP 5, PHP 7, PHP 8)

php_strip_whitespace返回刪除注釋和空格后的PHP源碼

說明

php_strip_whitespace(string $filename): string

返回刪除注釋和空格后 filename 的PHP源碼。這對實(shí)際代碼數(shù)量和注釋數(shù)量的對比很有用。 此函數(shù)與 命令行 下執(zhí)行 php -w 相似。

參數(shù)

filename

PHP文件的路徑。

返回值

在成功時(shí)返回過濾后的代碼,或者在失敗時(shí)返回空字符串。

注意:

此函數(shù)在PHP 5.0.1后以所述方式工作。之前它僅會(huì)返回一個(gè)空字符串。關(guān)于更多此BUG的信息與其行為,詳見BUG報(bào)告 ? #29606。

范例

示例 #1 php_strip_whitespace() 的例子

<?php
// PHP comment here

/*
 * Another PHP comment
 */

echo        php_strip_whitespace(__FILE__);
// Newlines are considered whitespace, and are removed too:
do_nothing();
?>

以上例程會(huì)輸出:

<?php
 echo php_strip_whitespace(__FILE__); do_nothing(); ?>

可以注意到PHP的注釋已不存在,成為第一個(gè)echo語句前的換行和空格。