您的位置:首页 > 其它

关于preg_match()函数的一点小说明

2017-01-14 18:28 309 查看
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )

返回值:匹配到返回 int 1, 匹配不到返回 int 0 , 错误发生时,返回false.

例子:preg_match("[b]/[/b]php/i", "PHP is the web scripting language of choice.")

关于$pattern,定界符不一定要是 /,如 /string/。当要匹配的字符串里含有 / 时,就不能用 /作为定界符了,可以用@ #等等。如"@php@i"

例子:preg_match('[b]@[/b]^(?:http://)?([^/]+)@i',"http://www.php.net/index.html", $matches);

另外i表示不区分大小写,但是不支持g(其他语言里表示匹配全部),匹配全部用preg_match_all()。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: