note 109820 added to function.strtr
| From: | patrick dot rauchfuss at gmail dot com | Date: | Fri, 24 Aug 2012 08:04:10 +0000 |
| Subject: | note 109820 added to function.strtr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190205@lists.php.net to get a copy of this message | ||
Here my solution of an classes recursive caseinsentive strtr..
<?php
class String
{
public static function stritr(&$string, $from, $to = NULL)
{
if(is_string($from))
$string = preg_replace("'$from'i", $to, $string);
else if(is_array($from))
{
foreach ($from as $key => $val)
self::stritr($string, $key, $val);
}
return $string;
}
}
// example:
$string = "Hello world. This is just a simple test";
print String::stritr($string, 'WorLd', 'foo');
// array example:
print String::stritr($string, array('WorLd' => 'foo', 'TEST' =>
'bar'));
?>
----
Server IP: 69.147.83.197
Probable Submitter: 82.135.98.118
----
Manual Page -- http://www.php.net/manual/en/function.strtr.php
Edit -- https://master.php.net/note/edit/109820
Del: integrated -- https://master.php.net/note/delete/109820/integrated
Del: useless -- https://master.php.net/note/delete/109820/useless
Del: bad code -- https://master.php.net/note/delete/109820/bad+code
Del: spam -- https://master.php.net/note/delete/109820/spam
Del: non-english -- https://master.php.net/note/delete/109820/non-english
Del: in docs -- https://master.php.net/note/delete/109820/in+docs
Del: other reasons-- https://master.php.net/note/delete/109820
Reject -- https://master.php.net/note/reject/109820
Search -- https://master.php.net/manage/user-notes.php