本文实例讲述了 php 字符串分割函数用法分享给大家供大家参考具体分析如下:
php 中 explode 和 split 函数用来分割字符串
explode 函数语法如下
explode(substring, string)
explode 函数通过子字符串进行分割, 效率比 split 要高 split 函数语法如下
split(pattern, string)
split 通过正则表达式对字符串进行分割, 效率相对 explode 要低, 但是功能强大
- <?php
- $list = explode("_","php_strting_function.html");
- print("explode() returns:\n");
- print_r($list);
- $list = split("[_.]","php_strting_function.html");
- print("split() returns:\n");
- print_r($list);
- ?>
输出结果如下:
- explode() returns:
- Array
- (
- [0] => php
- [1] => strting
- [2] => function.html
- )
- split() returns:
- Array
- (
- [0] => php
- [1] => strting
- [2] => function
- [3] => html
- )
来源: https://www.php1.cn/detail/php-24eb794254.html