array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.php-strip-whitespace.php', 1 => 'php_strip_whitespace', ), 'up' => array ( 0 => 'ref.misc.php', 1 => '杂项 函数', ), 'prev' => array ( 0 => 'function.pack.php', 1 => 'pack', ), 'next' => array ( 0 => 'function.sapi-windows-cp-conv.php', 1 => 'sapi_windows_cp_conv', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/misc/functions/php-strip-whitespace.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
php_strip_whitespace — 返回删除注释和空格后的PHP源码
返回删除注释和空格后 filename
的PHP源码。这对实际代码数量和注释数量的对比很有用。
此函数与 命令行 下执行 php -w 相似。
filename
PHP文件的路径。
示例 #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();
?>
以上示例会输出:
<?php echo php_strip_whitespace(__FILE__); do_nothing(); ?>
可以注意到PHP的注释已不存在,成为第一个echo语句前的换行和空格。