Home  >  Article  >  php教程  >  php中字符串函数substr()

php中字符串函数substr()

WBOY
WBOYOriginal
2016-06-13 08:51:101256browse

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

Statement:
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