php在字串中某些預定義的字元前加反斜線函數quotemeta()

來源:互聯網
上載者:User

執行個體

在預定義的字元前添加反斜線:

<?php$str = "Hello world. (can you hear me?)";echo quotemeta($str);?>

定義和用法

quotemeta() 函數在字串中某些預定義的字元前添加反斜線。

預定義的字元:

  • 句號(.)

  • 反斜線(\)

  • 加號(+)

  • 星號(*)

  • 問號(?)

  • 方括弧([])

  • 脫字型大小(^)

  • 貨幣符號($)

  • 圓括弧(())

提示:該函數可用於轉義擁有特殊意義的字元,比如 SQL 中的 ( )、[ ] 以及 * 。

注釋:該函數是二進位安全的。

文法

quotemeta(string)

參數 描述

string 必需。規定要檢查的字串。

技術細節

傳回值: 返回引用元字元的字串。

PHP 版本: 4+

更多執行個體

執行個體 1

在多個預定義的字元前添加反斜線:

<?php$str1 = "1 + 1 = 2";$str2 = "1 * 1 = 1";$str3 = "Could you borrow me 5$?";$str4 = "Are you not entertained? (I am..)";$str5 = "The caret [ ^ ] Looks like a hat!";echo quotemeta($str1)."<br>";echo quotemeta($str2)."<br>";echo quotemeta($str3)."<br>";echo quotemeta($str4)."<br>";echo quotemeta($str5)."<br>";?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.