note 111289 added to function.trim

From: Date: Sat, 02 Feb 2013 13:10:44 +0000
Subject: note 111289 added to function.trim
Groups: php.notes 
Request: Send a blank email to php-notes+get-193497@lists.php.net to get a copy of this message
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); ?> ---- Server IP: 69.147.83.199 Probable Submitter: 180.247.151.166 ---- Manual Page -- http://php.net/manual/en/function.trim.php Edit -- https://master.php.net/note/edit/111289 Del: integrated -- https://master.php.net/note/delete/111289/integrated Del: useless -- https://master.php.net/note/delete/111289/useless Del: bad code -- https://master.php.net/note/delete/111289/bad+code Del: spam -- https://master.php.net/note/delete/111289/spam Del: non-english -- https://master.php.net/note/delete/111289/non-english Del: in docs -- https://master.php.net/note/delete/111289/in+docs Del: other reasons-- https://master.php.net/note/delete/111289 Reject -- https://master.php.net/note/reject/111289 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193497) next »