In PHP
using str_replace
how is possible replace two words in a string with only one word (in my case is space and not word) ?
With javascript i used:
string.replace(/word-|-/g," ");
so i want replace this two words:
/word-
-/
But how is possible in php ? i tried to use also
preg_replace(array('/word-','-/')," ",$string);
but nothing :( i hope you can help me
This:
str_replace(array('/word-', '-/'), ' ', $string);
should work for you. The /
s in the JS example though are delimiters showing where the regex starts and ends. So in the PHP preg_replace
you'd need to do:
preg_replace(array('~/word-~','~-/~')," ",$string);
or maybe simpler:
preg_replace('~(/word-|-/)~'), " ",$string);
Note the above matches what you've stated but not what your JS is doing.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments