PHP Shield Keyword Implementation method _php example

Source: Internet
Author: User

This article introduced the PHP shielding keyword realization method, a total of two kinds of realization way, concretely as follows:

The first of these methods

The idea is to match the keyword with the positive, and replace the key word with another character.

 $STR = "/Your big Uncle | You're paralyzed | Sb| you the mother/";  Keyword Regular string  
 $string = "What the hell are you doing?"    Text string 
 echo preg_replace ($str, "*", $string);    Preg_replace () performs a matching and replacement of a regular expression

OK method The end is very simple to see people in the time can be based on the idea of their own first to think

Method Two

Ideas

1. Put the keyword in a txt document to be separated by a certain conformance, using the file_get_contents () function to read the keyword document

2. Use the function explode () to split the string into a series of cyclic array strpos () to find the matching keyword

Code

Header (' content-type:textml; charset=utf-8; '); 
function Strposfuck ($content) 
{   
$fuck = file_get_contents (' keyWords.txt ');  Read the keyword text information  
$content = Trim ($content);    $FUCKARR = explode ("\ n", $fuck);  Converts a keyword to an array for  
($i =0 $i < count ($FUCKARR), $i + +)   
{  
//$FUCKARR [$i] = Trim ($FUCKARR [$i]);  
if ($fuckArr [$i] = = "") {     
continue;  If the keyword is empty, skip this cycle   
# code ...   
}    
if (Strpos ($content, Trim ($FUCKARR [$i]))!= false)    
  {return    
  $fuckArr [$i];  return keyword     
  # code ...     
  }    if match to key word return false;  Returns False if there is no match to the 
  keyword 
  $content = "I met an SB in your uncle today";  
  $key = Strposfuck ($content); 
  if ($key) 
  {  
  echo exists a keyword. $key;  
  # code ...  
  } 
  else  
  {   
  echo ' OK '; 
  }

Be careful , be sure to go to the air.

The Strops () function returns the value of either false or the position of the keyword when judging the attention

After the success, you can think about how to return all the matching keywords to form a string or an array.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.