Home > php教程 > php手册 > body text

php中字符串函数substr()

WBOY
Release: 2016-06-13 08:51:10
Original
1262 people have browsed it

php中字符串函数substr()

语法:string substr(string $string int $start [,int $end]),该函数也是按字节(不是字符)来截取,在截取中文的时候要注意,而且截取的开始位置一定是在结束位置的左边,即总是从左往右截取。

$str="Hello world!";

echo substr($str,3),"
";//结果lo world!

echo substr($str,3,8),"
";//结果lo wo

echo substr($str,-6),"
";//此时第二个参数为负数表示从倒数第六个位置开始往后截取,结果为world

echo substr($str,-6,-3),"
";//此时第三个参数为负数时表示的是截取的长度,结果为wor

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!