Home  >  Article  >  Backend Development  >  (PHP) Regular expression-preg_quote-Usage of escaped regular expression characters

(PHP) Regular expression-preg_quote-Usage of escaped regular expression characters

黄舟
黄舟Original
2016-12-30 11:08:261262browse

<?php
/**
 * Created by PhpStorm.
 * User: Ollydebug
 * Date: 2015/11/15
 * Time: 10:20
 */

//preg_quote-转义正则表达式字符
//preg_quote()需要参数 str 并向其中 每个正则表达式语法中的字符前增加一个反斜线。这通常用于你有一些运行时字符串 需要作为正则表达式进行匹配的时候

$str = &#39;qwer{asdf}[1234]&#39;;

$str = preg_quote($str);

show($str);

function show($var){
    if(empty($var)){
        echo &#39;null&#39;;
    }elseif(is_array($var)||is_object($var)){
        // array,object
        echo &#39;<pre class="brush:php;toolbar:false">&#39;;
        print_r($var);
        echo &#39;
'; }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)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn