How to replace @
and .
symbols from an email address with -
symbol using preg_replace()
function in php ?
There is no need to use preg_replace
.
Use str_replace
instead:
$output = str_replace(array('@', '.'), '-', $input);
Since your search patterns are just strings, using string replacement using str_replace
is better as suggested in other answer.
Here goes the preg_replace
based answer:
$str = preg_replace('/@|\./','-',$str);
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