note 45316 added to function.trim

From: Date: Wed, 01 Sep 2004 22:24:51 +0000
Subject: note 45316 added to function.trim
Groups: php.notes 
Request: Send a blank email to php-notes+get-75911@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.trim.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45316 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45316&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45316&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#75911) next »