Home  >  Article  >  Backend Development  >  PHP string interception tutorial

PHP string interception tutorial

PHPz
PHPzOriginal
2016-07-29 09:04:2415000browse

获Php string Get SUBSTR and StRSTR Function

PHP string interception tutorial

Recommended tutorial: Php online tutorial


Php string to get

to obtain specified characters from the string string. Relevant functions are as follows:

 ●substr(): Get a part of it from a string

 ●strstr(): Find the position where the string first appears in another string, and return the position from that position to All characters at the end of the string

 ●subchr(): Same as strstr()

 ●strrchr(): Find the last occurrence of a string in another string and return all characters from that position to the end of the string Character

substr()

Syntax:

strrchr(): The function is used to get a part of it from a string and return a string.

string substr ( string string, int start [, int length] )
The parameter description is as follows:

Parameter DescriptionstringThe string to be processedstartStart position of the string, the starting position is 0, if it is negative, start from Starting from the specified position at the end of the stringlengthOptional, the length returned by the string, the default is until the end of the string, if it is negative, it is returned from the end of the stringExample:

Tips: If start is a negative number and length is less than or equal to start, then length is 0.

strstr()

Find the first occurrence of a string in another string and return all characters from that position to the end of the string, or FALSE if not found. Syntax:

string strstr ( string string, string needle )

The parameter description is as follows:

Parameter DescriptionstringThe string to be processed needleTo be The string to search for, if it is a number , then search for characters matching the numeric ASCII value

例子:

提示:该函数对大小写敏感。如需进行大小写不敏感的查找,请使用 stristr() 。

strchr()

同 strstr() 。

strrchr()

查找字符串在另一个字符串中最后一次出现的位置,并返回从该位置到字符串结尾的所有字符,如果没找到则返回 FALSE。

语法:

string strrchr ( string string, string needle )

该函数行为同 strstr() 函数,参数意义可参见上面 strstr() 函数参数说明。

例子:

运行例子,输出:

|CCC

结合 substr() 函数便可以实现 截取某个最后出现的字符后面的所有内容 这一功能:

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