PHP Function Reference

PHP php_strip_whitespace() Function



The PHP php_strip_whitespace() function returns the PHP source code in specified file with PHP comments and whitespace removed.

This function is useful for determining the amount of actual code in the script compared with the amount of comments.

Syntax

php_strip_whitespace(filename)

Parameters

filename Required. Specify the path to the PHP file.

Return Value

Returns the stripped source code on success, or an empty string on failure.

Example: php_strip_whitespace() example

In the example below the php_strip_whitespace() function is used with the current script to remove PHP comments and whitespace.

<?php
//a single line PHP comment

/*
  a multiple line PHP comment
*/

echo        php_strip_whitespace(__FILE__);
//newlines are considered whitespace, 
//and are also removed too
function myFunction() {
};
?>

The output of the above code will be:

<?php
 echo php_strip_whitespace(__FILE__); function myFunction() { }; ?>

❮ PHP Miscellaneous Reference