note 111289 deleted from function.trim by peehaa

From: Date: Tue, 06 Dec 2016 09:27:22 +0000
Subject: note 111289 deleted from function.trim by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208234@lists.php.net to get a copy of this message
Note Submitter: syn-attack at devilzc0de dot org ---- I think this is my implementation of trim... <?php /* * Function: "trim" * @str = source * @charlist = list of characters to be trimmed from the source * * Author: syn-attack@devilzc0de.org * Full documentation in http://php.net/manual/en/function.trim.php */ function __trim($str, $charlist = '') { $result = ''; /* list of forbidden chars to be trimmed */ $forbidden_list = array(" ", "\t", "\r", "\n", "\0", "\x0B"); if (empty($charlist)) { for ($i = 0; $i < strlen($str); $i++) { if (($str[$i] != $forbidden_list[0]) && ($str[$i] != $forbidden_list[1]) && ($str[$i] != $forbidden_list[2]) && ($str[$i] != $forbidden_list[3]) && ($str[$i] != $forbidden_list[4]) && ($str[$i] != $forbidden_list[5])) { $result .= $str[$i]; } } } else if (!empty($charlist)) { $is_not_same = true; for ($i = 0; $i < strlen($str); $i++) { for ($j = 0; $j < strlen($charlist); $j++) { if ($str[$i] != $charlist[$j]) { $is_not_same = true; } else if ($str[$i] == $charlist[$j]) { $is_not_same = false; break; } } if ($is_not_same == true) { $result .= $str[$i]; } } } return ($result); } $str = "Paulus Gandung Prakosa"; echo __trim($str); ?>

« previous php.notes (#208234) next »