PHP 函数 preg_grep()
语法
  array preg_grep ( string $pattern, array $input [, int $flags] );
定义和用法
返回给定数组input中与模式pattern 匹配的元素组成的数组.如果将flag设置为PREG_GREP_INVERT, 这个函数返回输入数组中与 给定模式pattern不匹配的元素组成的数组.
返回值
返回给定数组input中与模式pattern 匹配的元素组成的数组.
Example
下面是一段代码,这段代码复制并粘贴到一个文件中并验证结果。
    <?php
    $foods = array("pasta", "steak", "fish", "potatoes");
    // find elements beginning with "p", followed by one or more letters.
    $p_foods = preg_grep("/p(\w+)/", $foods);
    print "Found food is " . $p_foods[0];
    print "Found food is " . $p_foods[1];
    ?>
这将会产生以下结果:
    Found food is pasta
    Found food is potatoes
						上一篇: 函数 preg_split(...
			
						下一篇: 函数 preg-quote(...