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

黄舟
Release: 2023-03-04 13:28:01
Original
1262 people have browsed it

<?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; } } ?>
Copy after login

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)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!