[3] => category.php?id=6
)
[2] => Array
(
[0] => 首页
[1] => GSM手机
[2] => 双模手机
[3] => 手机配件
)
)
四、preg_split($pattern,$subject)
通过一个正则表达式分隔字符串
<?php echo "<pre>"; $str = "12,34:56;784;35,67:897:65"; //分隔字符串 $arr = preg_split("/[,;:]/",$str); print_r($arr); ?>
输出
Array
(
[0] => 12
[1] => 34
[2] => 56
[3] => 784
[4] => 35
[5] => 67
[6] => 897
[7] => 65
)
五、preg_quote($str)
转义正则表达式字符
正则表达式特殊字符有:. \ + * ? [ ^ ] $ ( ) { } = ! < > : -
<?php echo "<pre>"; echo preg_quote("(abc){10}");//在每个正则表达式语法的字符前增加一个反斜杠 ?>
输出
\(abc\)\{10\}
六、子存储
<?php echo "<pre>"; //子存储使用 $date="[2012-08-09],[2012,09-19],[2011/08,09],[2012/10/09],[2013,08,01]"; //将上面字串中合法的日期匹配出来 preg_match_all("/\[[0-9]{4}([\-,\/])[0-9]{2}\\1[0-9]{2}\]/",$date,$a); print_r($a); ?>
输出
Array
(
[0] => Array
(
[0] => [2012-08-09]
[1] => [2012/10/09]
[2] => [2013,08,01]
)
[1] => Array
(
[0] => -
[1] => /
[2] => ,