Php/func regex preg grep
来自菜鸟教程
PHP preg_grep()函数
例
从以“ p”开头的数组中获取项目:
<?php
$input = [
"Red",
"Pink",
"Green",
"Blue",
"Purple"
];
$result = preg_grep("/^p/i", $input);
print_r($result);
?>
定义和用法
The
preg_grep()
函数返回一个数组,该数组仅包含输入中与给定模式匹配的元素。
句法
preg_grep(pattern, input, flags)
参数值
| 参数 | 描述 |
|---|---|
| pattern | 需要。包含一个正则表达式,指示要搜索的内容 |
| input | 需要。字符串数组 |
| flags | 可选的。此功能只有一个标志。通过常量
|
技术细节
| 返回值: | 返回一个包含与提供的模式匹配的字符串的数组 |
| PHP版本: | 4+ |