In PHP, you do this to replace more then one value at a time.
<?php $string = "i am the foobar"; $newstring = str_replace(array('i', 'the'), array('you', 'a'), $string); echo $newstring; ?>
How do you do this in javascript?
Use javascript's .replace()
method, stringing multiple replace's together. ie:
var somestring = "foo is an awesome foo bar foo foo"; //somestring lowercase var replaced = somestring.replace(/foo/g, "bar").replace(/is/g, "or"); // replaced now contains: "bar or an awesome bar bar bar bar"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With