Home > Backend Development > PHP Tutorial > php字符串分割函数用法实例_PHP

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

WBOY
Release: 2016-06-01 11:06:13
Original
1112 people have browsed it

本文实例讲述了php字符串分割函数用法。分享给大家供大家参考。具体分析如下:

php中explode 和 split 函数用来分割字符串。

explode函数语法如下

explode(substring, string)
Copy after login

explode函数通过子字符串进行分割,效率比split要高 split函数语法如下

split(pattern, string)
Copy after login

split通过正则表达式对字符串进行分割,效率相对explode要低,但是功能强大

<&#63;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);
&#63;>
Copy after login

输出结果如下:

explode() returns:
Array
(
[0] => php
[1] => strting
[2] => function.html
)

split() returns:
Array
(
[0] => php
[1] => strting
[2] => function
[3] => html
)
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template