PHP uses the STRSTR () function to block spam reviews (by judging a mark) _php tutorial

Source: Internet
Author: User
The Strstr () function searches for the first occurrence of a string in another string. The function returns the remainder of the string (from the matching point). returns false if the searched string is not found.

Syntax: Strstr (String,search)

Parameter string, required. Specifies the string to be searched.
Parameter search, required. Specifies the string to search for. If the parameter is a number, the character that matches the ASCII value of the number is searched.
The function is case-sensitive. For a case-insensitive search, use STRISTR ().

Strstr () function Simple Demo

Copy the Code code as follows:
Echo strstr ("Hello nowamagic!", "nowamagic");
?>

Program Run Result:

nowamagic!

One more simple example.

Copy the Code code 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 Run Result:

@example. com

This function can be used in a lot of places. If your site spam comments a lot, most of the spam comments are linked, because to add backlinks, so you can use the following tips to eliminate these linked spam comments.

Copy the Code code as follows:
$content = $_post[' content '];
$garbage = Strstr ($content, "if ($garbage = = False)
{
Database Insert Code
}
Else
{
echo "";
}
?>

Well, that's probably it.

http://www.bkjia.com/PHPjc/313556.html www.bkjia.com true http://www.bkjia.com/PHPjc/313556.html techarticle The strstr () function searches for the first occurrence of a string in another string. The function returns the remainder of the string (from the matching point). If the searched string is not found, then ...

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.