note 45316 deleted from function.trim by aidan

From: Date: Thu, 02 Sep 2004 06:36:14 +0000
Subject: note 45316 deleted from function.trim by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75923@lists.php.net to get a copy of this message
Note Submitter: Felipe Alcacibar, falcacibar at hotmail dot com ---- I'made a special trim for uses with the plain files, then need read the content delimited for spaces or tabs. This function, strips the more than one tab or space, spaces and tabs, are replaced with spaces, and carrige return and newline are replaced with newline only. Enjoy x)... <?php function strim($string) { // you can use $string=trim(chop($string)); /* or while(preg_match("/\s+/", substr($string, 0, 1))) {; $string=substr($string, 1, strlen($string)); }; while(preg_match("/\s+/", substr($string, -1, 1))) {; $string=substr($string, 0, (strlen($string) - 1)); }; */ while(preg_match("/((\n\r|r\n){1}|(\t\ |\ \t){1}|\t{2}|\ {2})/", $string)) { while(preg_match("/(\n\r|\r\n){1}/", $string)){; $string=preg_replace("/(\n\r|\r\n){1}/", "\n", $string);} while(preg_match("/(\t\ |\ \t){1}/", $string)){; $string=preg_replace("/(\t\ |\ \t){1}/", " ", $string); }; while(strstr($string, "\t\t")){; $string=str_replace("\t\t", "\t", $string); }; while(strstr($string, " ")){; $string=str_replace(" ", " ", $string); }; } return $string; } ?>

« previous php.notes (#75923) next »