The PHPstrstr function is used to determine whether a string exists. Define and use the PHPstrstr () function to search for the first occurrence of a string in another string. This function returns the rest of the string (from the matching point ). If the definition and usage of PHP strstr are not found
The strstr () function searches for the first occurrence of a string in another string.
This function returns the rest of the string (from the matching point ). If the searched string is not found, false is returned.
Syntax
Strstr (string, search)
Parameters |
Description |
String |
Required. Specifies the string to be searched. |
Search |
Required. Specifies the string to be searched. If this parameter is a number, search for characters that match the ASCII value of the number. |
Tips and comments
Note: This function is binary secure.
Note: This function is case sensitive. Use stristr () to perform case-insensitive searches ().
Example
Example 1
The code is as follows:
Echo strstr ("Hello world! "," World ");
?>
Output:
World!
Example 2
In this example, we will search for the characters represented by the ASCII value of "o:
The code is as follows:
Echo strstr ("Hello world! ", 111 );
?>
Output:
O world!
PHP uses the strstr () function to stop spam comments.
If you have a lot of spam comments on your website and most spam comments contain links, you can use the following tips to prevent spam comments with links.
The code is as follows:
$ Content = $ _ POST ['content'];
$ Garbage = strstr ($ content, "if ($ garbage = false)
{
// Insert database code
}
Else
{
Echo "script" alert ('Your comments cannot carry a link '); history. go (-1); script ";
}
?>
PHP uses the REFERER root-residence access to jump to the address
For example, I developed a yellow page source code and transferred it to the webmaster's house. Previously set a demo program address: http://www.jb51.net and now this domain name needs to be used for other sites, and do not kill the original demo address failure what to do. Then I can use php referer to determine the source. if it is from the address of the webmaster download site, I will transfer it to the site domain name.
I just put the following code in index. php on the http://www.jb51.net site to get it from files.jb51.net access to my server frequently used software download http://s.jb51.net
You can go to the demo address on this page.
The code is as follows:
$ ReferHost = parse_url ($ _ SERVER ['http _ referer'], PHP_URL_HOST );
$ ValidDomain = 'files .jb51.net ';
$ Valid = strstr ($ referHost, $ validDomain) ==$ validDomain;
If (! Empty ($ valid )){
Echo 'script location. href = "http://s.jb51.net"; script ';
Exit;
}
The http://www.bkjia.com/PHPjc/313560.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/313560.htmlTechArticlePHP strstr defines and uses the strstr () function to search for the first appearance of a string in another string. This function returns the rest of the string (from the matching point ). If not found...