当前位置: 代码迷 >> 综合 >> PHP preg_match 应用
  详细解决方案

PHP preg_match 应用

热度:53   发布时间:2023-12-09 18:23:20.0

int preg_match(string pattern, string subject, array [matches]);
返回值: 整数/数组
函数种类: 资料处理
内容说明
本函数以 pattern 的规则来解析比对字符串 subject。比对结果返回的值放在数组参数 matches 之中,matches[0] 内容就是原字符串 subject、matches[1] 为第一个合乎规则的字符串、matches[2] 就是第二个合乎规则的字符串,余类推。若省略参数 matches,则只是单纯地比对,找到则返回值为 true。  

 

<?php

 


preg_match("/^(http:)?([^//]+)/i", "http://www.php.net/index.html/", $result);

print_r ($result );    //echo $result[0]; echo $result[1];echo $result[2];

echo $result;     //--输出true-

//-输出--Array ( [0] => http://www.php.net [1] => http:// [2] => www.php.net ) -------


?>