Hot Article
- Centos7 closes and restarts the system firewall and opens firewall ports
- How IID server uses Xshell to connect to Linux (centos) server
- BT panel forgets the background login URL, and the solution to the security entrance verification failure
- The php domain name points to ip, how to use the specified ip address to access a server in the url request domain name in curl mode
- How to purchase a dedicated server
- Error connecting to MySQL: Cant connect to MySQL server (10060)
What is the function of strpos() function in PHP? (Correct usage)
- Author:Sven
- Category:PHP technology
- Release Time:2022-11-29
The PHP strpos function is used to find the first occurrence of a string. Its syntax is strpos(string, find, start), the parameter string is required, specifying the string to be searched; find is required, specifying the string to be searched.
What is the function of the strpos() function in PHP? (Correct usage)
Using PHP's strpos()
function to determine whether a string contains a certain string
//The method of judging whether a certain string contains a certain string
if(strpos('www.iid.hk','iid') !== false){
echo 'contains';
}else{
echo 'does not contain';
}
PHP strpos() function
The strpos() function returns the position of the first occurrence of a string within another string. Returns false if the string is not found.
Syntax
- strpos(string,find,start) parameter description
- string Required. Specifies the string to be searched.
- find Required. Specifies the character to look for.
- start is optional. Specifies where to start the search.
Note: This function is case sensitive. For a case-insensitive search, use the stripos() function.
Edit this paragraph example
Output: 3
The method of judging whether a certain string contains a certain string
if(strpos('www.iid.hk','iid') !== false){
echo 'contains';
}else{
echo 'does not contain';
}
Many people use the following judgment method, which is wrong
if(strpos('www.iid.hk','iid') ){
echo 'contains';
}else{
echo 'does not contain';
}
The above can also get the correct result, but the method is wrong, if (strpos('idc-gz.com','idc-gz') ), then the correct result cannot be obtained, the reason is The position starts from 0, the first position is found, it is 0, 0 in php, it is not true, the above judgment will not be true, this point must be very careful!
The above is about the function of the strpos()
function in PHP? (Correct usage) After understanding all the content, I believe everyone can find out the problem. If you want to know more technology-related content, please pay attention to INTERNET DATA.