int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
返回值:匹配到返回 int 1, 匹配不到返回 int 0 , 错误发生时,返回false.
例子:preg_match("/php/i", "PHP is the web scripting language of choice.")
关于$pattern,定界符不一定要是 /,如 /string/。当要匹配的字符串里含有 / 时,就不能用 /作为定界符了,可以用@ #等等。如"@php@i"
例子:preg_match('@^(?:http://)?([^/]+)@i',"http://www.php.net/index.html", $matches);
另外i表示不区分大小写,但是不支持g(其他语言里表示匹配全部),匹配全部用preg_match_all()。
preg_replace ( $pattern
, $replacement
, $subject
[, int $limit
= -1 [, int &$count
]] )
这个函数替换是替换全部,并没有preg_replace_all()方法。