Home  >  Article  >  Backend Development  >  php字符串截取的简单方法_php技巧

php字符串截取的简单方法_php技巧

WBOY
WBOYOriginal
2016-05-17 08:57:11992browse

复制代码 代码如下:

strpos(string,find,start)

实例:
复制代码 代码如下:



输出6
复制代码 代码如下:

substr(string,start,length)

其中start的参数

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

复制代码 代码如下:



输出world

strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。

该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。

复制代码 代码如下:

strstr('abc@jb51.net', '@', TRUE); //参数设定true, 返回查找值@之前的首部,abc
strstr( 'abc@jb51.net', '@'); //默认返回查找值@之后的尾部,@jb51.net
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