array preg_split ( string $pattern , string $subject [, int $limit = -1 [, int $flags = 0 ]] )
参数说明如下:注意:这将会改变返回数组中的每一个元素,使每个元素成为一个由第 0 个元素为分隔后的子串、第 1 个元素为该子串在 subject 中的偏移量组成的数组。
<?php echo "<pre>"; $subject = 'PHP教程:http://c.biancheng.net/php/, Python教程:http://c.biancheng.net/python/'; $pattern = '/[\s,:]+/'; print_r( preg_split($pattern, $subject) ); print_r( preg_split($pattern, $subject, 3) ); ?>执行以上程序的结果如下:
Array
(
[0] => PHP教程
[1] => http://c.biancheng.net/php/
[2] => Python教程
[3] => http://c.biancheng.net/python/
)
Array
(
[0] => PHP教程
[1] => http://c.biancheng.net/php/
[2] => Python教程:http://c.biancheng.net/python/
)
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有