note 88091 modified in function.str-replace by danbrown
| From: | danbrown@php.net | Date: | Fri, 09 Jan 2009 18:46:26 +0000 |
| Subject: | note 88091 modified in function.str-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148999@lists.php.net to get a copy of this message | ||
I´ve just made gabriel dot totoliciu at ddnet dot ro's function a little smaller, hope you
like it.
NOTE: this function is not 100% secure, since the subject can have the temp replace
<?php
function stru_replace($search, $replace, $subject){
if(!is_array($search)) {
$search = array($search);
}
if(!is_array($replace)){
$replace = array($replace);
}
foreach($search as $key => $value){
//used "|{}#PHP_IsAwesome" to try make the temp replace secure, the bigger the better
$subject = str_replace($value, "|{}#PHP_IsAwesome".$key."|{}#PHP_IsAwesome",
$subject);
}
foreach($search as $key => $value){
$subject = str_replace("|{}#PHP_IsAwesome".$key."|{}#PHP_IsAwesome",
$replace[$key], $subject);
}
return($subject);
}
?>
--was--
TO: gabriel dot totoliciu at ddnet dot ro
I´ve just made your function a little smaller, hope you like it.
NOTE: this function is not 100% secure, since the subject can have the temp replace
<?
function stru_replace($search, $replace, $subject){
if(!is_array($search)) {
$search = array($search);
}
if(!is_array($replace)){
$replace = array($replace);
}
foreach($search as $key => $value){
//used "|{}#PHP_IsAwesome" to try make the temp replace secure, the bigger the better
$subject = str_replace($value, "|{}#PHP_IsAwesome".$key."|{}#PHP_IsAwesome",
$subject);
}
foreach($search as $key => $value){
$subject = str_replace("|{}#PHP_IsAwesome".$key."|{}#PHP_IsAwesome",
$replace[$key], $subject);
}
return($subject);
}
?>
http://php.net/manual/en/function.str-replace.php