php字符串函数学习之substr()
这篇文章主要介绍了php字符串函数学习之substr(),本文讲解了它的定义和用法、参数描述、提示和注释以及多个使用示例 ,需要的朋友可以参考下
/*
定义和用法
substr() 函数返回提取的子字符串, 或者在失败时返回 FALSE。
语法
substr(string,start,length)
参数 描述
string 必需。规定要返回其中一部分的字符串。
start
必需。规定在字符串的何处开始。
非负数 - 从 string 的 start 位置开始,从 0 开始计算.
负数 - 从 string 结尾处向前数第 start 个字符开始。
如果 string 的长度小于或等于 start,将返回 FALSE。
length
可选。规定要返回的字符串长度。默认是直到字符串的结尾。
正数 - 从 start 处开始最多包括 length 个字符(取决于 string 的长度)。
负数 - 去除从string 结尾处向前length个字符
如果提供了值为 0,FALSE 或 NULL 的 length,那么将返回一个空字符串。
*/
$str = "abcdefghijklmn";
$rest = substr($str, 0); // 返回 "abcdefghijklmn"
echo $rest . "
";
$rest = substr($str, 1, 3); // 返回 "bcd"
echo $rest . "
";
$rest = substr($str, -3); // 返回 "lmn"
echo $rest . "
";
$rest = substr($str, -3, 2); // 返回 "lm"
echo $rest . "
";
$rest = substr($str, 1, -3); // 返回 "bcdefghijk"
echo $rest . "
";
$rest = substr($str, -7, -3); // 返回 "hijk"
echo $rest . "
";
?>

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment