Filter keywords, we usually carry out data submission will be used to filter before and after the white space, in fact, when we are familiar with the regular, we completely use the regular to filter out the user input space, and with this can be filtered out of any position of the space; in the extension maybe that's why the name can't contain spaces. , of course, the real reason is because the language string naming restrictions and not the space is filtered out, the idea here is that the cross-domain memory of their own learning knowledge, conducive to memory and learning;
Keyword blocking is the social software must do the function, when we are familiar with the regular, we completely use the regular to filter out the user input space, and with regular can filter out any space, the specific method of shielding the keyword can be referred to this article.
"problem" keyword blocking is the social software must do the function, of course, is generally the product of the middle and late to do; different product specifications, follow the product operation, you can
"Method" we look at this problem from a technical point of view, to achieve a function the latter said that the implementation of a demand, its methods are various, the focus is to find suitable for our current products; What we're going to say here is the front-end JS processing method, the back-end PHP processing method
"JS Method"
Text to block var str = ' Xiao Li, Xiao Ming and Xiao Hong are the principals ' students; in this small family, the headmaster is our teacher! ';//keyword group, this can be defined at the front end, can also come from the background var arr = [' Xiao Li ', ' Xiao Ming ', ' Little Red ', ' family ', ' headmaster '];var res = str.replace (New RegExp (Arr.join (' | '), ' img ') ), ' * ', Console.log (res),//*, * and * are students; in this small *, * is our teacher!
"Php Method"
Block text $str = ' Xiao Li, Xiao Ming and Xiao Hong are the principals ' students; in this small family, the headmaster is our teacher! ';//keyword Group $arr = [' Xiao Li ', ' Xiao Ming ', ' Little Red ', ' family ', ' Headmaster '];echo preg_replace ('/'. Join ($arr, ' | '). ' /', ' * ', $str);//*, * and * are students; in this small * inside, * is our teacher!
The difference is the method, the same is the idea;
The above is the use of regular expressions to block the keyword method, we hope to help.