substr() 函数返回字符串的一部分。
注释:如果 start 参数是负数且 length 小于或等于 start,则 length 为 0。
语法:
substr(string,start,length)
参数 | 描述 |
---|---|
string | 必需。规定要返回其中一部分的字符串。 |
start | 必需。规定在字符串的何处开始。
|
length | 可选。规定被返回字符串的长度。默认是直到字符串的结尾。
|
"; echo substr("Hello world",1)."
"; echo substr("Hello world",3)."
"; echo substr("Hello world",7)."
"; echo substr("Hello world",-1)."
"; echo substr("Hello world",-10)."
"; echo substr("Hello world",-8)."
"; echo substr("Hello world",-4)."
"; echo substr("Hello world",0,10)."
"; echo substr("Hello world",1,8)."
"; echo substr("Hello world",0,5)."
"; echo substr("Hello world",6,6)."
"; echo substr("Hello world",0,-1)."
"; echo substr("Hello world",-10,-2)."
"; echo substr("Hello world",0,-6)."
"; echo substr("Hello world",-2-3)."
"; ?>
输出结果
d
ello world
lo world
orld
d
ello world
lo world
orld
Hello worl
ello wor
Hello
world
Hello worl
ello wor
Hello
world
上一篇:python打开文件模式
下一篇:python将pdf按照图片保存