We often want to filter out unnecessary sensitive words in the message system. The following is a simple implementation. In fact, we can use the database to store this information, then you can find out and make a judgment.
| The Code is as follows: |
Copy code |
/Use a regular expression) $ Str = "aa = !! | Bb =@| cc =##| dd =$ $ | ee =%%| ff = ^ | gg = & amp ;"; $ Arr = explode ('|', $ str ); Foreach ($ arr as $ key = & gt; $ val) { $ Array [] = explode ('=', $ val ); } Print_r ($ array ); For ($ I = 0; $ I & lt; count ($ array); $ I ++) { $ A1 [] = & quot;/& quot;. $ array [$ I] [0]. & quot;/& quot ;; $ A2 [] = $ array [$ I] [1]; } Unset ($ arr ); $ Message = & #039; Haha is an anti-social era WOCAO madE & #039 ;; Echo $ message. & #039; <br> '; Print preg_replace ($ a1, $ a2, $ message); // supports parameter arrays, but the parameters are case sensitive. <Strong> </strong> print eregi_replace ($ arr1, array ('!! ',' @ ',' # ',' $ ',' % ',' ^ ',' & Amp ;'), $ message); // arrays are not supported, but the parameters are case-insensitive. |