PHP中substr()与explode()函数用法分析_php技巧
May 16, 2016 pm 08:30 PM
explode
php
substr
function
本文实例讲述了PHP中substr()与explode()函数用法。分享给大家供大家参考。具体方法如下:
substr(string,start,length):本函数将字符串 string 的第 start 位起的字符串取出 length 个字符,若 start 为负数,则从字符串尾端算起,若可省略的参数 length 存在,但为负数,则表示取到倒数第 length 个字符,实例代码如下:
复制代码 代码如下:
echo substr("abcdef", 1, 3); // 返回 "bcd"
echo substr("abcdef", -2); // 返回 "ef"
echo substr("abcdef", -3, 1); // 返回 "d"
echo substr("abcdef", 1, -1); // 返回 "bcde"
?>
echo substr("abcdef", -2); // 返回 "ef"
echo substr("abcdef", -3, 1); // 返回 "d"
echo substr("abcdef", 1, -1); // 返回 "bcde"
?>
explode(separator,string,limit):本函数将字符串分割为数组 separator 规定在哪里分割,string 要分割的字符串,limit 可选,数组元素的最大数目,实例代码如下:
复制代码 代码如下:
$str = "abc|bck|fhq|nui";
print(explode("|",$srt)); //输出array([0]=>abc,[1]=>bck,[2]=>fhq,[3]=>nui)
?>
print(explode("|",$srt)); //输出array([0]=>abc,[1]=>bck,[2]=>fhq,[3]=>nui)
?>
希望本文所述对大家的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
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

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