php之substr()详解

简介: <div style="margin:0px 0px 0px 15px; padding:20px 0px; border-width:1px 0px; border-top-style:solid; border-bottom-style:solid; border-top-color:rgb(170,170,170); border-bottom-color:rgb(170,170,1

定义和用法

substr() 函数返回字符串的一部分。

语法

substr(string,start,length)
参数 描述
string 必需。规定要返回其中一部分的字符串。
start

必需。规定在字符串的何处开始。

  • 正数 - 在字符串的指定位置开始
  • 负数 - 在从字符串结尾的指定位置开始
  • 0 - 在字符串中的第一个字符处开始
length

可选。规定要返回的字符串长度。默认是直到字符串的结尾。

  • 正数 - 从 start 参数所在的位置返回
  • 负数 - 从字符串末端返回

提示和注释

注释:如果 start 是负数且 length 小于等于 start,则 length 为 0。

例子

例子 1

<?php
echo substr("Hello world!",6);
?>

输出:

world!

例子 2

<?php
echo substr("Hello world!",6,5);
?>

输出:

world
相关文章
|
7月前
|
PHP
PHP 字符串
PHP 字符串
25 0
|
4月前
|
PHP
php中elseif 和else if的区别
@(黑线)以前貌似看到if这里,就直接跳了,可是今天再读文档,又发现了点东西... @(乖)可能你已经知道了php存在elseif 和else if,保留了c的风格。
24 0
|
7月前
|
PHP
PHP 字符串长度
PHP 字符串长度
35 0
|
8月前
|
PHP
php字符串
php字符串
42 0
|
PHP 数据安全/隐私保护
php中0和字符串比较时注意的问题
php中0和字符串比较时注意的问题
107 0
|
PHP 开发者
php echo对象,php __toString
php echo对象,php __toString
66 0
|
SQL PHP
PHP中str_replace高级使用你知道吗?
PHP中str_replace高级使用你知道吗?
98 0
PHP中str_replace高级使用你知道吗?
|
PHP Java .NET

热门文章

最新文章