Home >Backend Development >PHP Tutorial >(PHP) Regular expression-preg_grep function usage

(PHP) Regular expression-preg_grep function usage

黄舟
黄舟Original
2016-12-30 11:06:292309browse

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

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

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

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

show($arr);

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_grep function usage. 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