php字符串分割函数用法实例

yipeiwu_com6年前PHP代码库

本文实例讲述了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
)

希望本文所述对大家的php程序设计有所帮助。

相关文章

剖析 PHP 中的输出缓冲

我们先来看一段代码:     〈?php     for ($i=10; $i〉0;&...

php实现将Session写入数据库

使用session_set_save_handler()函数,将Session的内容写入数据库 <?php /* *@author Fahy *数据库为m...

PHP 变量定义和变量替换的方法

有两种方法把变量替换到字符串中——简单的方法和复杂的方法。 简单的方法是把变量名放在双引号字符串或heredoc中: $who = ‘Kilroy'; $where = ‘here';...

php输出全球各个时区列表的方法

本文实例讲述了php输出全球各个时区列表的方法。分享给大家供大家参考。具体实现方法如下: <?php $timezones = array ( '(GMT-12:00...

php从身份证获取性别和出生年月

话不多说,请看代码: //通过身份证号查询出性别与生日 $birth = strlen($idcard)==15 ? ('19' . substr($idcard, 6,...