欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          php怎么用正則匹配某個字符并刪除

          兩種方法:1、用preg_replace()將匹配字符替換為空字符,語法“preg_replace('/指定字符/i','',$str)”。2、用preg_filter(),語法“preg_filter('/字符/i','',$str)”。

          php怎么用正則匹配某個字符并刪除

          本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版、DELL G3電腦

          php利用正則匹配某個字符并刪除的兩種方法

          方法1:使用preg_replace()進行正則替換

          preg_replace() 函數(shù)可以執(zhí)行正則表達式的搜索和替換

          只需要利用preg_replace()執(zhí)行正則表達式搜索指定字符并將其替換為空字符即可。

          <?php header('content-type:text/html;charset=utf-8');    $str = '1132hell0 2313'; $pattern = '/l/i'; $replacement = ''; echo preg_replace($pattern, $replacement, $str); ?>

          php怎么用正則匹配某個字符并刪除

          方法2:使用preg_filter()進行正則替換

          preg_filter()和preg_replace() 函數(shù)一樣,可以執(zhí)行正則表達式的搜索和替換。

          只需執(zhí)行正則表達式搜索指定字符并將其替換為空字符即可。

          <?php header('content-type:text/html;charset=utf-8');    $str = '1132hell0 2313'; echo "原字符串:".$str."<br>"; $pattern = '/3/i'; $replacement = ''; echo "處理后:".preg_filter($pattern, $replacement, $str); ?>

          php怎么用正則匹配某個字符并刪除

          說明: preg_replace() 和 preg_filter() 的區(qū)別

          preg_filter() 函數(shù)只返回匹配成功的結果,而 preg_replace() 返回所有結果,不管是否匹配成功。

          推薦學習:《PHP視頻教程》

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號