<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Return source with stripped comments and whitespace</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.php-check-syntax.html">php_check_syntax</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.show-source.html">show_source</a></div> <div class="up"><a href="ref.misc.html">Misc. Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.php-strip-whitespace" class="refentry"> <div class="refnamediv"> <h1 class="refname">php_strip_whitespace</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">php_strip_whitespace</span> — <span class="dc-title">Return source with stripped comments and whitespace</span></p> </div> <div class="refsect1 description" id="refsect1-function.php-strip-whitespace-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>php_strip_whitespace</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> )</div> <p class="para rdfs-comment"> Returns the PHP source code in <em><code class="parameter">filename</code></em> 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 <strong class="command">php -w</strong> from the <a href="features.commandline.html" class="link">commandline</a>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.php-strip-whitespace-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <p class="para"> Path to the PHP file. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.php-strip-whitespace-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The stripped source code will be returned on success, or an empty string on failure. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> This function works as described as of PHP 5.0.1. Before this it would only return an empty string. For more information on this bug and its prior behavior, see bug report <a href="http://bugs.php.net/29606" class="link external">» #29606</a>. </p> </p></blockquote> </div> <div class="refsect1 examples" id="refsect1-function.php-strip-whitespace-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3783"> <p><strong>Example #1 <span class="function"><strong>php_strip_whitespace()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// PHP comment here<br /><br />/*<br /> * Another PHP comment<br /> */<br /><br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">php_strip_whitespace</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// Newlines are considered whitespace, and are removed too:<br /></span><span style="color: #0000BB">do_nothing</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> <?php echo php_strip_whitespace(__FILE__); do_nothing(); ?> </pre></div> </div> <div class="example-contents"><p> Notice the PHP comments are gone, as are the whitespace and newline after the first echo statement. </p></div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.php-check-syntax.html">php_check_syntax</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.show-source.html">show_source</a></div> <div class="up"><a href="ref.misc.html">Misc. Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>