php基础32:正则匹配-修饰符

时间:2023-03-09 23:44:06
php基础32:正则匹配-修饰符
<?php

    //正则表达式--修饰符一般放在//的外面

    //1. i 表示不区分大小写
    $model = "/php/";
    $string = "php";
    echo(preg_match($model, $string));

    $model = "/php/";
    $string = "PHP";
    echo(preg_match($model, $string));

    $model = "/php/i";
    $string = "PHP";
    echo(preg_match($model, $string))."<hr>";

    //2. m 表示匹配首位的时候,如果遇到换行,也应该承认是结尾
    $model = "/php$/";
    $string = "this is php\n, is good";
    echo(preg_match($model, $string));

    $model = "/php$/m";
    $string = "this is php\n, is good";
    echo(preg_match($model, $string))."<hr>";

    //3. x忽略正则中的空白
    $model = "/p h p/";
    $string = "php";
    echo(preg_match($model, $string));

    $model = "/p h p/x";
    $string = "php";
    echo(preg_match($model, $string))."<hr>";

    //4. A表示强制从头开始匹配
    $model = "/php/";
    $string = "phpdddddddddddd";
    echo(preg_match($model, $string));

    $model = "/php/";
    $string = "ddddddphp";
    echo(preg_match($model, $string));

    $model = "/php/A";
    $string = "ddddddphp";
    echo(preg_match($model, $string));

    $model = "/php/A";
    $string = "phpdddddd";
    echo(preg_match($model, $string))."<hr>";

    //U:禁止贪婪模式
?>