php_strip_whitespace()
php_strip_whitespace() — Return source with stripped comments and whitespace.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Returns the PHP source code in filename with PHP comments and whitespace removed. This may be useful for determining the amount of actual code in your scripts compared with the amount of comments. This is similar to using php -w from the commandline.
Signature
php_strip_whitespace(string $filename): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $filename | string | Path to the PHP file. |
Return value
The stripped source code will be returned on success, or an empty string on failure. Note: This function respects the value of the short_open_tag ini directive. This function respects the value of the short_open_tag ini directive.
Example
A runnable snippet:
// PHP comment here /* * Another PHP comment */ echo php_strip_whitespace(__FILE__); // Newlines are considered whitespace, and are removed too: do_nothing();
Output:
<?php echo php_strip_whitespace(__FILE__); do_nothing(); ?>
All PHP 8.5 built-in functions
Reference card built from the PHP manual page php_strip_whitespace() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.