This code down ignores related: in $SeQuery when it is on first position, right? $sitepos = strpos($SeQuery, 'related:'); if (!$sitepos === false) { return; } PHP: Now i would liek that all bad words and profanity words be ignored, and i m not sure if this is right code, please let me know before i add it to my sites: if (preg_match('/(bad word1|bad word2|bad word3)/i', $SeQuery)); { exit; } PHP: Thanks
Emm is that statement right ? Is so there must be a function that already changes bad words, perhaps it would be easier to work with that, and set-up an if condition on that function, example if your the username or something....
This is filter for autocreating tags. And i want only clean tags to be created. Fo if i put word F***k inside preg match i want it to stop with creating tag for all tags that have this word inside. Do you think my preg_match is working in this way?
Try this // FULL MATCH SOLUTION $badwords = array("bad word1", "bad word2"); $tags = array("good word1", "good word2", "bad word1"); $intersect = array_intersect($badwords, $tags); $cleanTags = array_diff($tags, $intersect); print_r($cleanTags); Code (markup): or this // PARTIAL MATCH SOLUTION $cnt = 0; foreach($tags as $tag) { foreach($badwords as $bd) { if (stripos($tag, $bd) !== false) unset($tags[$cnt]); } $cnt++; } print_r($tags); Code (markup):
Guys i m not trying to filter tags. I have tool that creates tags from search querryes. So i want to filter search querys which are $SeQuery. I use this code for filtering and not creating querys which start with related: $sitepos = strpos($SeQuery, 'related:'); if (!$sitepos === false) { return; } PHP: But i need to filter and skip all tags which have bad words like f words p words and you know common bad adult stuff. So i create this above the code i write up there: Original code: if (preg_match('/(piÄk|sex|kurac|ass|jeb|pizd|seks|shit|www|bitch|dick|pićk|picka|picke|picko|picki|kurc|fuvk|fuk|fuck|whore|naked|gole|goli|lesbo)/i', $SeQuery)); { exit; } PHP: But in last 3 days there is single tag created, so i m thinking that this code is maybe wrong or needs tweak or what could be reason for not creating tags, maybe some of the words i filter is too common? Maybe it was just exiting everything so i changed the code to: if (preg_match('/(piÄk|sex|kurac|ass|jeb|pizd|seks|shit|www|bitch|dick|pićk|picka|picke|picko|picki|kurc|fuvk|fuk|fuck|whore|naked|gole|goli|lesbo)/i', $SeQuery)) { exit; } else { return; } PHP: Is this better?
If you need to skip tags with bad words, you shouldn't exit. The following solution assumes that tags are separated by ','. I hope that the following code will help you to find a solution to your problem. define("TAGS_SEPARATOR", ","); $SeQuery = "fucker, sex, hello"; $SeQuery = preg_replace('#[^a-z0-9,]+#si', "", $SeQuery); $pattern = '#(piÄk|sex|kurac|ass|jeb|pizd|seks|shit|www|bitch|dick|pićk|picka|picke|picko|picki|kurc|fuvk|fuk|fuck|whore|naked|gole|goli|lesbo)#si'; $tags = explode(TAGS_SEPARATOR, $SeQuery); $cnt = 0; foreach($tags as $tag) { if (preg_match($pattern, $tag)) unset($tags[$cnt]); $cnt++; } print_r($tags); Code (markup):
Hmm maybe your code will help me in some parts but problem is that this are not tags and are not seperated. this are querrys. Search Engine Querrys. So What this script do is if you do a search for let say "Sexy Old Ladies" on a search engine. Then this querrys is taken into script and goes trough lots of process if it will be created to tag or not. So i m not trying to filter tags i m trying to filter querrys containing bad words. Or the words i dont like to be created as tags. In script are other various filters: see this part: $SePage = $se['Page']; $SeQuery = strtolower($se['Query']); $SeDomain = strtolower($se['Se']); $SeLang = strtolower($se['SeLang']); //WE IGNORE Bad words or words we dont like if (preg_match('/(piÄk|sex|kurac|ass|jeb|pizd|seks|shit|www|bitch|dick|pićk|picka|picke|picko|picki|kurc|nude|fuvk|fuk|fuck|whore|naked|gole|goli|lesbo)/i', $SeQuery)) { exit; } else { return; } //WE IGNORE searches over 40 characters and under 4 characters if ( strlen($SeQuery) > 40 ) {return; } if ( strlen($SeQuery) < 4 ) {return; } //WE IGNORE NUMBER-ONLY SEARCHES if (is_numeric($SeQuery)) {return; } //WE IGNORE "http:"-SEARCHES $sitepos = strpos($SeQuery, 'http:'); if (!$sitepos === false) { return; } //WE IGNORE "CACHE:"-searches $sitepos = strpos($SeQuery, 'cache:'); if (!$sitepos === false) { return; } //WE IGNORE "SITE:"-SEARCHES $sitepos = strpos($SeQuery, 'site:'); if (!$sitepos === false) { return; } //WE IGNORE "RELATED:"-SEARCHES $sitepos = strpos($SeQuery, 'related:'); if (!$sitepos === false) { return; } PHP: Now i m not sure if this exit is good command. If you think this will work please give me a green light or if you think that this exit or pre_match command need to replaced with something else please help me then. Thanks allot for your responding.
So, if I search for "Sexy Old Ladies", do you want to skip the word Sexy and create tags for "Old" and "Ladies", or skip the complete search phrase ("Sexy Old Ladies")?
I think that the following will do the job $SePage = $se['Page']; $SeQuery = strtolower($se['Query']); $SeDomain = strtolower($se['Se']); $SeLang = strtolower($se['SeLang']); $badWordsPattern = '/(piÄk|sex|kurac|ass|jeb|pizd|seks|shit|www|bitch|dick|pićk|picka|picke|picko|picki|kurc|nude|fuvk|fuk|fuck|whore|naked|gole|goli|lesbo)/i'; $ignorePattern = '/(http|cache|site|related):/i'; if ( is_numeric($SeQuery) || preg_match($badWordsPattern, $SeQuery) || preg_match($ignorePattern, $SeQuery) || ($len = strlen($SeQuery)) < 4 || $len > 40) return; Code (markup):