If you have a lot of spam comments on your website, most of the spam comments contain links, because you need to add reverse links, so you can use the following tips to prevent the strstr () function with links from searching for the first appearance 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)
The string parameter, required. Specifies the string to be searched.
Search parameter, required. Specifies the string to be searched. If this parameter is a number, search for characters that match the ASCII value of the number.
This function is case sensitive. Use stristr () to perform case-insensitive searches ().
A simple demonstration of strstr () functions
The code is as follows:
Echo strstr ("Hello NowaMagic! "," NowaMagic ");
?>
Program running result:
NowaMagic!
Another simple example
The code is as follows:
$ Email = 'name @ example.com ';
$ Domain = strstr ($ email ,'@');
Echo $ domain; // prints @ example.com
// $ User = strstr ($ email, '@', true); // As of PHP 5.3.0
// Echo $ user; // prints name
?>
Program running result:
@ Example.com
This function can be used in many places. 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 ";
}
?>
Well, that's probably the case.