1.php 的 preg_replace 與 str_replace 都是默認 /g 的,全部替換
2.如果需要使用正則表達式 需要使用preg_replace,代碼如下:
- <?php
- $a= "abc defa
- bcd ef";
- $b= preg_replace("//t|a/","",$a);
- echo($b);
- /*
- 輸出:
- bc def
- bcd ef
- */
- ?>
另外對比一下js中的replace,感覺php的語法,不優美,代碼如下:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <script>
- vara="a b";
- console.log(a.replace(//t/g,""));
- </script>
- </body>
- </html>
新聞熱點
疑難解答