当前位置:Gxlcms > PHP教程 > (PHP)正则表达式-preg_grep函数用法

(PHP)正则表达式-preg_grep函数用法

时间:2021-07-01 10:21:17 帮助过:12人阅读

<?php
/**
 * Created by PhpStorm.
 * User: Ollydebug
 * Date: 2015/11/13
 * Time: 22:55
 */

//阉割版preg_filter
//preg_grep函数只会去做匹配的操作,不做替换

$pattern = '/[0-9]/';
$subject = array('weuy','r3ui','76as83','s','0ck9');

$arr = preg_grep($pattern,$subject);

show($arr);

function show($var){
    if(empty($var)){
        echo 'null';
    }elseif(is_array($var)||is_object($var)){
        // array,object
        echo '<pre>';
        print_r($var);
        echo '</pre>';
    }else{
        //string,int,float
        echo $var;
    }
}

?>

以上就是(PHP)正则表达式-preg_grep函数用法的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!

人气教程排行