定義済み文字の前にバックスラッシュを追加します:
<?php
$str = "Hello world. (can you hear me?)";
echo quotemeta($str);
?>
例の実行 »
quotemeta() 関数は、文字列内のいくつかの定義済み文字の前にバックスラッシュを追加します。
定義済みの文字は以下の通りです:
チップ: この関数は、SQL の ( )、[ ]、* などの特別な意味を持つ文字をエスケープするために使用することができます。
注: この関数はバイナリセーフです。
quotemeta(string)
パラメータ | 説明 |
---|---|
string | 必須。チェックする文字列を指定する |
返り値: | クォートされたメタ文字の文字列を返します |
---|---|
PHP バージョン: | 4+ |
定義済の多くの文字の前にバックスラッシュを追加します:
<?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>";
?>
例の実行 »