note 81985 added to function.str-replace
| From: | jaimthorn at yahoo dot com | Date: | Sat, 22 Mar 2008 17:59:04 +0000 |
| Subject: | note 81985 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137325@lists.php.net to get a copy of this message | ||
If all you want to do is remove characters from a string, then this solution is about 7 times
faster:
/**
* Removes certain characters from a string.
*
* @param string $string the string to be stripped.
* @param string $chars a string containing all the characters to be removed from $string. May be
empty.
* @return string the original $string with the characters from $chars removed.
*/
function RemoveChars($string, $chars)
{
return isset($chars{0}) ? str_replace($chars{0}, "", strtr($string, $chars,
str_pad($chars{0}, strlen($chars), $chars{0}))) : $string;
}
----
Server IP: 83.137.20.135
Probable Submitter: 24.132.180.10
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/81985
Del: integrated -- https://master.php.net/note/delete/81985/integrated
Del: useless -- https://master.php.net/note/delete/81985/useless
Del: bad code -- https://master.php.net/note/delete/81985/bad+code
Del: spam -- https://master.php.net/note/delete/81985/spam
Del: non-english -- https://master.php.net/note/delete/81985/non-english
Del: in docs -- https://master.php.net/note/delete/81985/in+docs
Del: other reasons-- https://master.php.net/note/delete/81985
Reject -- https://master.php.net/note/reject/81985
Search -- https://master.php.net/manage/user-notes.php