Suppose the string One two (three)
In PHP, in order to replace the spaces with a dash, and parentheses with an empty string, I’d do it like this: str_replace( array( ' ', '(', ')' ), array( '-' ), $key )
, because search
arg is an array, replace
is an array also, and replace has fewer elements than search, so the remaining elements from search are replaced with an empty string…
I’m not very good in JS, so I needed to achieve something similar, like turning One two (three)
to One-two-three
, and tried with chained replace commands. But it doesn’t work in the expected way. Obviously I’m doing something wrong, but what is it?
var text="one two (three)";
alert(text.replace("(", "").replace(")", "").replace(" ", "-"));