mdnghtblue Posted July 26, 2007 Share Posted July 26, 2007 I don't know much about regular expressions, and I'm trying to figure something out. I didn't write the following code: $altbegin[] = "/([^\^\.\+\[\] ])/i"; $altend[] = "(\\\*|#|\\\^|\\1)([\.\_\~\`\+\=\* \-]*)"; $altbegin[] = "/uc/i"; $altend[] = "(uc|u|cu|\*|\*c|u\*)"; $altbegin[] = "/a/i"; $altend[] = "[a@ÁÂÃÄÅàáâãäå]"; $altbegin[] = "/b/i"; $altend[] = "[bß]"; $altbegin[] = "/c/i"; $altend[] = "[c©Çç\(\{\[]"; $altbegin[] = "/d/i"; $altend[] = "(d|Ð|ð|\|\))"; $altbegin[] = "/e/i"; $altend[] = "[eÆÈÉÊËèéêë3]"; $altbegin[] = "/f/i"; $altend[] = "[fƒ]"; $altbegin[] = "/g/i"; $altend[] = "[g9]"; $altbegin[] = "/h/i"; $altend[] = "(\|-\||[h])"; $altbegin[] = "/l/i"; $altend[] = "(£|i)"; $altbegin[] = "/i/i"; $altend[] = "[il|\\\/!ÌÍÎÏìíîï]"; $altbegin[] = "/j/i"; $altend[] = "(_\||[j])"; $altbegin[] = "/k/i"; $altend[] = "(\|\(|\|\(|[k])"; $altbegin[] = "/m/i"; $altend[] = "n"; $altbegin[] = "/n/i"; $altend[] = "(\|\\\\\\\\\||[mnÑñ])"; $altbegin[] = "/o/i"; $altend[] = "u"; $altbegin[] = "/u/i"; $altend[] = "[ou0ÒÓÔÕÖòóôõöÙÚÛÜØøùúûüµ]"; $altbegin[] = "/r/i"; $altend[] = "[r®]"; $altbegin[] = "/s/i"; $altend[] = "[s\$§]"; $altbegin[] = "/y/i"; $altend[] = "[yÿýÝ]"; $altbegin[] = "/^\(\\\\\\*\|#\|\\\\\\^\|/i"; $altend[] = "("; $swear_words = Array([insert swear words here]); function swearCheck(&$str) { global $config, $altbegin, $altend, $swear_words; $str = ereg_replace("\"",""",$str); $str = strip_tags($str,"<em><b><i><u><font><strong><h3><p><li><ul>"); $str2 = "- ".stripslashes(strip_tags($str))." -"; $fs = "(".preg_replace($altbegin,$altend,"fucker").")*(".preg_replace($altbegin,$altend,"sucker").")*"; for ($i = 0; $i < count($swear_words); $i++) { $word = preg_replace($altbegin,$altend,$swear_words[$i]); if (eregi("(.+[^A-z])($word)$fs([^A-z].+)",$str2,$vars)) { TheEnd("Profanity (even words like '$swear_words[$i]') is not allowed in $config[servname]!<BR><b>Profanity found in the following context:</b><p>...".substr($vars[1],-100)."<b>$vars[2]</b>".substr($vars[count($vars)-1],0,100)."..."); } } } I know it's the swear filter, but I'm not really sure how it works. (and not sure what exactly is contained in the altbegin and altend arrays. The previous maintainer of this code added "com" to the filter (to prevent spamming), and now I want to take it out, but I didn't see in the $swear_words array. How do I remove it from the filter? Quote Link to comment https://forums.phpfreaks.com/topic/61919-solved-regex-newbie-question/ Share on other sites More sharing options...
mdnghtblue Posted July 29, 2007 Author Share Posted July 29, 2007 bump Anyone have any ideas or explanations? I've been trying to understand this on my own, not working. =/ Quote Link to comment https://forums.phpfreaks.com/topic/61919-solved-regex-newbie-question/#findComment-309841 Share on other sites More sharing options...
effigy Posted July 30, 2007 Share Posted July 30, 2007 Adding some test code should help: ### Create a list of words that will be considered swear words. $swear_words = Array( 'Damn', 'Poop', ); ### Create a list of words to test against the filter. $words = array('Dam', 'Damn it!', 'Egad!', 'Poop...'); foreach ($words as $word) { echo "Checking <b>$word</b>...<br>"; swearCheck($word); } ### Add the code you posted. You define what the swear words are and they are transformed into expressions (you can see these by echoing out $word after it is defined). The $altbegin array is the "search for" array, and the $altend array is the "replace with" array. They are paired together. For example: $altbegin[] = "/uc/i"; $altend[] = "(uc|u|cu|\*|\*c|u\*)"; If your swear word contains "uc" it will be transformed into the pattern "(uc|u|cu|\*|\*c|u\*)" which matches "uc", "u", "cu", "*", "*c", or "u*". The function is not efficient because it recreates the patterns on every call and for every word checked. I don't see the "com" you're referring to. Is it in another piece of code? Quote Link to comment https://forums.phpfreaks.com/topic/61919-solved-regex-newbie-question/#findComment-311352 Share on other sites More sharing options...
mdnghtblue Posted July 31, 2007 Author Share Posted July 31, 2007 I'll try putting in some test code in to see how it works. The code that stops "com" from being used has got to be in the code I posted above. I couldn't find it in the swearwords array, so I thought it was hidden in one of the regular expressions. The filter thinks "com" is "cum", so when someone tries to use an email address or URL with "com" in it, they'll get the following error message: Profanity (even words like 'cum') is not allowed in the game! Quote Link to comment https://forums.phpfreaks.com/topic/61919-solved-regex-newbie-question/#findComment-312054 Share on other sites More sharing options...
effigy Posted July 31, 2007 Share Posted July 31, 2007 O's are grouped with U's here: $altbegin[] = "/o/i"; $altend[] = "u"; $altbegin[] = "/u/i"; $altend[] = "[ou0ÒÓÔÕÖòóôõöÙÚÛÜØøùúûüµ]"; Quote Link to comment https://forums.phpfreaks.com/topic/61919-solved-regex-newbie-question/#findComment-312231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.