note 77624 added to function.php-strip-whitespace

From: Date: Thu, 06 Sep 2007 06:21:49 +0000
Subject: note 77624 added to function.php-strip-whitespace
Groups: php.notes 
Request: Send a blank email to php-notes+get-130235@lists.php.net to get a copy of this message
Notice: In my last comment for this function I failed to add some important parts of the function. So I have re-added it here. Feel free to delete my earlier comment. Thanks! --- To use php_strip_whitespace in (PHP 4 >= 4.2.0) you could try the function below. This function also helps solve the issues with php_strip_whitespace not fully removing new lines and extra whitespace's in HTML when embedded with PHP. <?php if (!defined ('T_ML_COMMENT')) { define ('T_ML_COMMENT', T_COMMENT); } if (!defined ('T_DOC_COMMENT')) { define ('T_DOC_COMMENT', T_ML_COMMENT); } function StripWhitespace($sFileName) { if ( !is_file($sFileName) ) { return false; } $sContent = implode('', file($sFileName)); $aTokens = token_get_all($sContent); $bLast = false; $sStr = ''; for ( $i = 0, $j = count($aTokens); $i < $j; $i++ ) { if ( is_string($aTokens[$i]) ) { $bLast = false; $sStr .= $aTokens[$i]; } else { switch ( $aTokens[$i][0] ) { case T_COMMENT: case T_ML_COMMENT: case T_DOC_COMMENT: break; case T_WHITESPACE: if (!$bLast) { $sStr .= ' '; $bLast = true; } break; default: $bLast = false; $sStr .= $aTokens[$i][1]; break; } } } $sStr = trim($sStr); $sStr = str_replace("\n", "", $sStr); $sStr = str_replace("\r", "", $sStr); return $sStr; } ?> ---- Server IP: 129.16.214.50 Probable Submitter: 83.249.91.209 ---- Manual Page -- http://www.php.net/manual/en/function.php-strip-whitespace.php Edit -- https://master.php.net/note/edit/77624 Del: integrated -- https://master.php.net/note/delete/77624/integrated Del: useless -- https://master.php.net/note/delete/77624/useless Del: bad code -- https://master.php.net/note/delete/77624/bad+code Del: spam -- https://master.php.net/note/delete/77624/spam Del: non-english -- https://master.php.net/note/delete/77624/non-english Del: in docs -- https://master.php.net/note/delete/77624/in+docs Del: other reasons-- https://master.php.net/note/delete/77624 Reject -- https://master.php.net/note/reject/77624 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130235) next »