Sensitive word filtering

Source: Internet
Author: User
Tags strtok
Sensitive word filtering if the user inputs
$ Str = "input 123 ";

Next I wrote abc.txt with about one thousand entries.
Bad guy | 1 fire gun | 1 super bad guy | 1 ....


How to use this txt file to check and filter $ str1; for efficiency, seek advice


Reply to discussion (solution)

Efficiency batch read filtering ..

Construct the trie tree from abc.txt and match the tree.
Algorithm in essence

Construct the trie tree from abc.txt and match the tree.
Hello, the algorithm is in the essence area. how can I call it when I see it as a class?
Not applicable ~ Tragedy. please be more detailed. thank you very much.
In addition, why does my file contain "| 1" at the end of each line?

Replace all the items | 1. people's things are useful to others.

Replace all the items | 1. people's things are useful to others.
Thank you for your answers. I still haven't touched my mind. I only knew that one row had been read before the question was answered.
Please give it a fish. most of the fish are Concepts. I have not reached the limit yet ~

The ttrie class of http://bbs.csdn.net/topics/390221822 is used as an example.

Trie = new ttrie=foreach(file('abc.txt ') as $ r) $ trie-> set (strtok ($ r,' | '); $ s = <TXT input content badgex 123TXT; // only recognize print_r ($ trie-> match ($ s )); /* get Array ([0] => input content [1] => bad guy [2] => 123) * // remove the dictionary word $ trie-> savematch = 0; print_r ($ trie-> match ($ s);/* Array ([0] => input content [1] => 123 )*/

Obviously, you have already met your needs.
When the output result is displayed, the connected array is a string.

If you want to highlight the keyword, you can do this.
Class mytrie extends ttrie {function B () {$ this-> buffer [] =''. Array_pop ($ this-> buffer ).'';}}$ Trie = new mytrie‑foreach(file('abc.txt') as $ r) $ trie-> set (strtok ($ r, '|'), 'B '); $ s = <TXT input content: 123TXT; print_r ($ trie-> match ($ s )); /* get Array ([0] => input content [1] =>Bad Guy= This is highlighted in [2] => 123 )*/

Actually, the fish has already been given to you, so it's better to do it yourself.

In order to reuse the instantiated object, we should also add at the beginning of the match method
    $this->buffer = array();    $this->input = 0;    $this->backtracking = 0;
To reinitialize the data pointer

The moderator is too mighty.

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.