関数 quotemeta
関数 quotemeta は、文字列内の各特殊文字の前にバックスラッシュを追加します。
以下の文字がエスケープされます: . \ + * ? [ ^ ] ( $ )。
この関数は、処理する文字列という1つのパラメータを受け取ります。
構文
quotemeta(string);
例
単純な文字列での特殊文字のエスケープ:
<?php
echo quotemeta('Hello.world (test)');
?>
コード実行結果:
'Hello\.world \(test\)'
例
複数の特殊文字を含む文字列のエスケープ:
<?php
echo quotemeta('1+1=2? [maybe]');
?>
コード実行結果:
'1\+1\=2\? \[maybe\]'
例
特殊文字を含まない文字列の処理:
<?php
echo quotemeta('simple text');
?>
コード実行結果:
'simple text'
関連項目
-
関数
addslashes,
スラッシュで文字列をエスケープします -
関数
preg_quote,
正規表現の文字をエスケープします