DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Replace Working As PHP Str_replace //JavaScript Function
<a href="http://jsfromhell.com">Useless JavaScript implementation of the php function str_replace.</a>
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com
function replace(f, r, s){
var ra = r instanceof Array, sa = s instanceof Array, l = (f = [].concat(f)).length, r = [].concat(r), i = (s = [].concat(s)).length;
while(j = 0, i--)
while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j < l);
return sa ? s : s[0];
}





