Definition and usage
The strpos () function returns the position where the string first appears in another string.
If this string is not found, false is returned.Syntax
Strpos (string, find, start)
Parameters
Description
This article describes how php uses substr () and strpos () to search for a specific character in a string. it involves the use of substr () and strpos () functions in php, for more information about how php uses substr () and strpos () to search
The reason why a comma is separated from Strpos is because it prevents finding matches, such as finding 1 and 12 in the array, then the result can be found, respectively, in the 1 before and after the addition, is to distinguish. foreach
In php, The strstr, strpos, substr, strrchr, and stripos functions are usually used to find out whether a character exists in a string. If you need to know about them, please refer to them.
1. strstr-first appearance of the search string
String
PHP in a character to find another string, whether there is a strpos, this function usage, often many people use the inverse, the correct usage is Strpos (string,search), the front is the original string, followed by the original string to query the
In a longer string this finds matching strings or characters, where STRSTR () and STRCHR () are exactly the same.Cases:echo strstr (' Why all you ', ' you ');Output:YouIf you are:echo strstr (' Why all you ', ' you ');Then no outputThe Stristr ()
The strpos () function returns the position where the string first appears in another string. If this string is not found, false is returned.
Strpos (string, find, start)String required: Specifies the string to be searched.Required: Specifies the
strpos– find where the string first appears
stripos– find where strings first appear (case insensitive)
strrpos– calculates the last occurrence of the specified string in the target string
Strripos– calculates the location of the last
String Strstr (String $haystack, mixed $needle [, bool $before _needle = false])1. $haystack the string to be searched, $needle What to look for2. Returns a part of the string if found, or false if no3, the function is case-sensitive, if you want to
String Strstr (String $haystack, mixed $needle [, bool $before _needle = false])1. $haystack the string to be searched, $needle What to look for2. Returns a part of the string if found, or false if no3, the function is case-sensitive, if you want to
The strlen () function returns the length (number of characters) of the string code:PHP Echo strlen ("Hello world!" );? >The above code will output: The Strpos () function is used to find a character or a specified text within a string.If a match is
PHP Strpos () function
PHP String function definition and usage
The Strpos () function returns the position where the string first appears in another string.
If the string is not found, it returns false. Grammar
Strpos (String,find,start)
Definition and usageThe Strpos () function returns the position of the first occurrence of a string in another string.If the string is not found, false is returned.GrammarStrpos (String,find,start)
Parameters
Description
Do you have any experience with PHP development, for a string to get, if you want to specifically detect whether itContains a specific character or substring, always can not find a good method, or can not do at all, forced to use
Role:1. Determine the position of a string in another string2. Determine if a string contains a string Strpos ($str, $char), starting on the left, where the character appears, case-sensitive; Stripos($str, $char), start on the left, where
PHP is often used to process string characters. php's built-in character functions provide very powerful functions that can basically complete most character processing operations, for example, use the str_split function to convert a character
The example in this article describes the way PHP uses substr () and Strpos () to find a particular character in a string. Share to everyone for your reference. The specific analysis is as follows:
Requirement: Look for the character in the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.