note 63922 added to function.php-strip-whitespace
| From: | heavyraptor at osu1 dot php dot net | Date: | Mon, 03 Apr 2006 23:29:03 +0000 |
| Subject: | note 63922 added to function.php-strip-whitespace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107255@lists.php.net to get a copy of this message | ||
My previous post was ok, but there where some problems; that's why I got this code, which is
identical to the original function of PHP, because its the same code (not exactly beacuse I changed
some little things to make it easier).
Enjoy
<?php
// Replaces the Function for users with PHP-Version < 5.0.1
if (!function_exists('php_strip_whitespace')) {
function php_strip_whitespace($file)
{
if (!is_scalar($file)) {
user_error('php_strip_whitespace() expects parameter 1 to be string, ' .
gettype($file) . ' given', E_USER_WARNING);
return;
}
$source = file_get_contents($file);
$tokens = token_get_all($source);
$source = '';
$was_ws = false;
foreach ($tokens as $token) {
if (is_string($token)) {
$source .= $token;
} else {
list($id, $text) = $token;
switch ($id) {
case T_COMMENT:
case T_ML_COMMENT:
case T_DOC_COMMENT:
break;
case T_WHITESPACE:
if ($was_ws !== true) {
$source .= ' ';
}
$was_ws = true;
break;
default:
$was_ws = false;
$source .= $text;
break;
}
}
}
return $source;
}
}
?>
----
Server IP: 66.163.161.117
Probable Submitter: 200.107.2.237
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.php-strip-whitespace.php
Edit -- http://master.php.net/note/edit/63922
Del: integrated -- http://master.php.net/note/delete/63922/integrated
Del: useless -- http://master.php.net/note/delete/63922/useless
Del: bad code -- http://master.php.net/note/delete/63922/bad+code
Del: spam -- http://master.php.net/note/delete/63922/spam
Del: non-english -- http://master.php.net/note/delete/63922/non-english
Del: in docs -- http://master.php.net/note/delete/63922/in+docs
Del: other reasons-- http://master.php.net/note/delete/63922
Reject -- http://master.php.net/note/reject/63922
Search -- http://master.php.net/manage/user-notes.php