PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.14.1
Last Build: March 10, 2017 13:28pm (PST)

psStrReplaceList()
Replace a list (key/val array) in a string


Description:

Returns a string with all the key/val pairs from an array replaced


Usage:

$str = psStrReplaceList($string,$array);


Example:


$ary['_color_'] = "red";
$ary['_sku_'] = "23423";

$template = "SKU: _sku_ / Color: _color_";

$str = psStrReplaceList($template,$ary);




Code:

function psStrReplaceList($str,$ary)
{
foreach ($ary as $key=>$val)
{
$str = str_replace($key,$val,$str);
}
return $str;
}

Changlelog:


See Also

And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site