Home >Backend Development >PHP Tutorial >(PHP) Regular expression-preg_quote-Usage of escaped regular expression characters
<?php /** * Created by PhpStorm. * User: Ollydebug * Date: 2015/11/15 * Time: 10:20 */ //preg_quote-转义正则表达式字符 //preg_quote()需要参数 str 并向其中 每个正则表达式语法中的字符前增加一个反斜线。这通常用于你有一些运行时字符串 需要作为正则表达式进行匹配的时候 $str = 'qwer{asdf}[1234]'; $str = preg_quote($str); show($str); function show($var){ if(empty($var)){ echo 'null'; }elseif(is_array($var)||is_object($var)){ // array,object echo '<pre class="brush:php;toolbar:false">'; print_r($var); echo ''; }else{ //string,int,float echo $var; } } ?>
The above is the content of (PHP) regular expression-preg_quote-escaping regular expression characters. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!