search
Homephp教程php手册示例讲解PHP函数preg_grep()的使用

示例讲解PHP函数preg_grep()的使用

Jun 13, 2016 am 11:07 AM
grepphpforintroduceusefunctionusofExampleexplain

我们今天为大家介绍的PHP函数preg_grep()就是PHP语言中,众多功能强大的函数之一,希望大家在阅读后能够对这一函数优异个深刻的认识。

函数原型:array preg_grep (string $pattern, array $input)
PHP函数preg_grep()返回一个数组,其中包括了$input数组中与给定的$pattern模式相匹配的单元。对于输入数组$input中的每个元素,preg_grep()也只进行一次匹配。代码6.3给出的示例简单地说明了preg_grep()函数的使用。

PHP函数preg_grep()代码6.3 数组查询匹配

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> ?php  </span></span></span></li>
<li>
<span>$</span><span class="attribute">subjects</span><span> = </span><span class="attribute-value">array</span><span>(  </span>
</li>
<li class="alt"><span>"Mechanical Engineering", "Medicine",  </span></li>
<li><span>"Social Science", "Agriculture",  </span></li>
<li class="alt"><span>"Commercial Science", "Politics"  </span></li>
<li><span>);  </span></li>
<li class="alt"><span>//匹配所有仅由有一个单词组成的科目名  </span></li>
<li>
<span>$</span><span class="attribute">alonewords</span><span> = </span><span class="attribute-value">preg_grep</span><span>("/^[a-z]*$/i"<br>, $subjects);  </span>
</li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
</ol>

通过以上这段PHP函数preg_grep()的代码示例,希望能够为读者起到一个加深印象的作用。


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment