Home > Article > Backend Development > Usage analysis of preg_replace regular replacement in php [replace multiple values at one time]
The example in this article describes the usage of preg_replace regular replacement in php. Share it with everyone for your reference, the details are as follows:
1.php’s preg_replace and str_replace are both default /g, replace them all
2. If you need to use regular expressions, you need to use preg_replace
<?php $a = "abc defa bcd ef"; $b= preg_replace("/\t|a/","",$a); echo($b); /* 输出: bc def bcd ef */ ?>
In addition, comparing replace in js, I feel that the syntax of php is not beautiful
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> var a="a b"; console.log(a.replace(/\t/g,"")); </script> </body> </html>
The running effect diagram is as follows:
I hope this article will help The above will be helpful to everyone in PHP programming.
For more analysis on the usage of preg_replace regular replacement in PHP [replacing multiple values at one time], please pay attention to the PHP Chinese website for related articles!