preg_match 函数

preg_match 执行正则匹配表达式

int preg_match (string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0]]])

$partten 搜搜索的模式 字符串

$subject 输入字符串

$matches 若提供了参数 matches 它将被填充为搜索结果 $matches[0] 包含完整模式匹配到的文本$matches[1] 将包含第一个捕获子组匹配到的文本,以此类推。

$flags 

PREG_OFFSET_CAPTURE若传递此标记对于每一个出现的匹配会附加字符串偏移量

$offset 从指定位置开始搜索

返回值 返回 pattern 匹配的次数 0 或 1 在第一次匹配后会停止搜索 i 不区分大小写

<?php

  if(preg_match("/php/i"), "php is the web scripting language of choice.")){

    echo "查找到匹配字符串 php";

  }else{

    echo "未发现匹配的字符串 php";

  };  

 

posted @ 2018-03-17 11:32  haha瓜  阅读(322)  评论(0编辑  收藏  举报