1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| preg_match ( string $pattern , string $subject [,$matches]) 搜索subject与pattern给定表达式匹配,若无$matches,成功返回1,否则返回0,若有$matches,符合的字符串部分将输出到$matches数组中,只要匹配到一个符合条件的就结束查找,
preg_match_all ( string $pattern , string $subject , array &$matches [, int $flags = PREG_PATTERN_ORDER [, int $offset = 0]) 搜索subject中所有匹配pattern给定正则表达式 的匹配结果并且将它们以flag指定顺序输出到matches中
preg_split(string $pattern , string $subject [, int $limit = -1 [, int $flags = 0 ]]) 用正则表达式pattern分割subject,返回分割后的字符串数组,指定了limit则最多返回 limit 个子串,如果 limit 是 -1,则没有限制
preg_replace(mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]]) 搜索subject中匹配pattern的部分, 以replacement进⾏替换
preg_replace_callback ( mixed $pattern , callback $callback , mixed $subject [, int $limit = -1 [, int &$count ]] ) 用callback 替代 replacement 进行替换字符串的计算,其他方面等同于 preg_replace()。调用时回调函数得到的参数是从subject 中匹配到的结果。若subject是数组则返回数组,其他返回替换后的字符串。
$preg = "/\.(baidu|sina)\./is”;//.baidu.或者。sinna符合的部分,不区分大小写,将字符串视为单⾏,换⾏符做普通字符看待,使“.”匹配任何字符看待
|