The Strstr () function searches for a string that appears for the first time in another string. The function returns the remainder of the string (from a match point). returns false if the searched string is not found.
Syntax: Strstr (String,search)
Parameter string, required. Specify the string to be searched for.
Parameter search, required. Specify the string to search for. If the argument is a number, searches for characters that match the numeric ASCII value.
This function is sensitive to case sensitivity. For case insensitive searches, use STRISTR ().
Strstr () function Simple Demo
Copy Code code as follows:
<?php
Echo strstr ("Hello nowamagic!", "nowamagic");
?>
Program Run Result:
nowamagic!
One more simple example.
Copy Code code as follows:
<?php
$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 Run Result:
@example. com
This function can be used in a lot of places. If your site has a lot of spam comments, most spam comments are linked because you want to add backlinks, so you can use the following tips to get rid of these linked spam comments.
Copy Code code as follows:
<?php
$content = $_post[' content '];
$garbage = Strstr ($content, "<a");
if ($garbage = = False)
{
Database Insert Code
}
Else
{
echo "<script>alert (' your comments cannot have links"); History.go ( -1);</script> ";
}
?>
Well, that's probably it.