Home>Article>Backend Development> How to intercept string length in php

How to intercept string length in php

Lisa Kudrow
Lisa Kudrow Original
2019-08-30 10:37:36 6568browse

How to intercept string length in php

PHP String Get

is used to get the specified string from the string.

Relevant functions are as follows:

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

strstr(): Finds the first occurrence of a string in another string and returns all characters from that position to 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.

Related recommendations: "PHP Tutorial"

substr()

substr() function is used to extract from a string Get part of it and return a string.

Syntax:

string substr ( string string, int start [, int length] )

Parameter description is as follows:

How to intercept string length in php

Example:

Tips

If start is negative and length is less than or equal to start, 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, Returns FALSE if not found.

Syntax:

string strstr ( string string, string needle )

Parameter description is as follows:

How to intercept string length in php

Example:

Tips

This function is case sensitive. For case-insensitive search, use stristr() .

strchr()

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, if If not found, return FALSE.

Syntax:

string strrchr ( string string, string needle )

This function behaves the same as the strstr() function. For the meaning of the parameters, please refer to the strstr() function parameter description above.

Example:

Run the example, output:

|CCC

Combined with the substr() function, you can intercept all the content after the last character that appears:

The above is the detailed content of How to intercept string length in php. For more information, please follow other related articles on the PHP Chinese website!

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