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.