分隔字符串函数在php中我们会用到explode与preg_split函数,但是小编用到最多的就是直接以一个字符分开了,如果有多个字符串我们好像就不知道如何使用此函数来分隔字符串了,下文来给各位介绍一下explode用法。
explode最简单用法
在本例中,我们将把字符串分割为数组:
代码如下 | 复制代码 |
$str = "Hello world. It's a beautiful day."; |
但如果碰到下面函数我们要如何来解决"祛痘、痘印#抗氧化:活肤滋润#对抗唇纹:提拉紧致#控油:保湿#改善唇色";
例子
代码如下 | 复制代码 |
$string="祛痘、痘印#抗氧化:活肤滋润#对抗唇纹:提拉紧致#控油:保湿#改善唇色"; $arr=explode('#',str_replace(array(":"),'#',$string)); 或者使用preg_split方法达到相同的效果 $arr = preg_split( "/ (#|:) /", $string ); |
发现这样非常的好用了哦,多个不同规则我们都可以一条语句搞写哦。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool