Source of: /manual/en/function.php-strip-whitespace.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.misc.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.php-strip-whitespace.php',
1 => 'php_strip_whitespace',
),
'up' =>
array (
0 => 'ref.misc.php',
1 => 'Misc. Functions',
),
'prev' =>
array (
0 => 'function.php-check-syntax.php',
1 => 'php_check_syntax',
),
'next' =>
array (
0 => 'function.show-source.php',
1 => 'show_source',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<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>
<a name="function.php-strip-whitespace.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">string</span> <span class="methodname"><b>php_strip_whitespace</b></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$filename</tt></span>
)</div>
<p class="para rdfs-comment">
Returns the PHP source code in <i><tt class="parameter">filename</tt></i>
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.php" class="link">commandline</a>.
</p>
</div>
<a name="function.php-strip-whitespace.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">filename</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Path to the PHP file.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.php-strip-whitespace.returnvalues"></a><div class="refsect1 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><p><b class="note">Note</b>:
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>.
<br />
</p></blockquote>
</div>
<a name="function.php-strip-whitespace.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 <b>php_strip_whitespace()</b> example</b></p>
<div class="example-contents programlisting">
<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 para"><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 para"><p>
Notice the PHP comments are gone, as are the whitespace and newline
after the first echo statement.
</p></div>
</div><p>
</p>
</div>
</div><?php manual_footer(); ?>