PHP 轉義Regex字元: preg_quote_PHP教程

來源:互聯網
上載者:User

PHP 轉義Regex字元: preg_quote


preg_quote — 轉義Regex字元

string preg_quote ( string $str [, string $delimiter = NULL ] )

preg_quote()需要參數str並向其中 每個Regex文法中的字元前增加一個反斜線. 這通常用於你有一些運行時字串 需要作為Regex進行匹配的時候.

Regex特殊字元有: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -

參數

str

輸入字串

delimiter

如果指定了選擇性參數delimiter, 它也會被轉義. 這通常用於 轉義PCRE函數使用的分隔字元. /是最通用的分隔字元.

傳回值

返迴轉義後的字串.

preg_quote()樣本

$keywords = '$40 for a g3/400';
$keywords = preg_quote($keywords, '/');
echo $keywords; // 返回 \$40 for a g3\/400
?>

http://www.bkjia.com/PHPjc/951492.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/951492.htmlTechArticlePHP 轉義Regex字元: preg_quote preg_quote 轉義Regex字元 string preg_quote ( string $str [, string $delimiter = NULL ] ) preg_quote()需要參數str並向其...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.