(PHP) Regular expression-preg_grep function usage

黄舟
Release: 2023-03-04 13:22:01
Original
2195 people have browsed it

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

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


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!