note 92968 added to function.str-replace
| From: | Ashus at osu1 dot php dot net | Date: | Mon, 17 Aug 2009 12:46:01 +0000 |
| Subject: | note 92968 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159562@lists.php.net to get a copy of this message | ||
I needed a function to replace the same string with values of an array. I'm using it to fill in
some things after having it translated.
<?php
function replace_with_array($what, $with, $s)
{
$a = explode($what, $s);
$s = '';
$c = count($a);
for($i=0;$i<$c;$i++)
{$s .= $a[$i].(($i+1<$c)?((isset($with[$i]))?$with[$i]:$what):'');}
return $s;
}
echo replace_with_array('
',
array('<span>','</span>'),
'foobarraboof.');
?>
----
Server IP: 147.32.160.17
Probable Submitter: 82.209.8.34
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/92968
Del: integrated -- https://master.php.net/note/delete/92968/integrated
Del: useless -- https://master.php.net/note/delete/92968/useless
Del: bad code -- https://master.php.net/note/delete/92968/bad+code
Del: spam -- https://master.php.net/note/delete/92968/spam
Del: non-english -- https://master.php.net/note/delete/92968/non-english
Del: in docs -- https://master.php.net/note/delete/92968/in+docs
Del: other reasons-- https://master.php.net/note/delete/92968
Reject -- https://master.php.net/note/reject/92968
Search -- https://master.php.net/manage/user-notes.php