How to replace two different characters with one character using the preg_replace () function?

How to replace the characters @ and . to an email address with a symbol - using the preg_replace() function in php?

+4
source share
2 answers

Since your search patterns are just strings, using string replacement using str_replace better than the other answer says.

Here's the answer of preg_replace :

 $str = preg_replace('/@|\./','-',$str); 
+4
source

No need to use preg_replace .

Use str_replace :

 $output = str_replace(array('@', '.'), '-', $input); 
+14
source

Source: https://habr.com/ru/post/1379470/


All Articles