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

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

Jun 01, 2016 am 11:06 AM
php function Split string usage

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

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

explode函数语法如下

1

explode(substring, string)

Copy after login

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

1

split(pattern, string)

Copy after login

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

1

2

3

4

5

6

7

8

<&#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

输出结果如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

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程序设计有所帮助。

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles