scarhand Posted October 16, 2007 Share Posted October 16, 2007 I'm trying to set up a word censor for a script I'm working on. Heres the script (please ignore the smiley parser, that works perfect): <?php $censors_query = "SELECT * FROM censors"; $censors_result = mysql_query($censors_query); $bwn = 0; while($row = mysql_fetch_assoc($censors_result)) { $badwords[$bwn] = $row['word']; $bwn++; } class parser { var $parse_smilies; var $smiley_url; var $parse_censors; function parser() { global $smilies; if ($smilies == 'yes') { $smilies = 'true'; } else { $smilies = 'false'; } $this->parse_smilies = $smilies; $this->smiley_url = "/smileys"; $this->parse_censors = true; } function parse($data) { $data = htmlentities($data); if($this->parse_smilies) { $data = $this->_parse_smilies($data); } if($this->parse_censors) { $data = $this->_parse_censors($data); } return $data; } function _parse_smilies($data) { $smilies = array( '' => 'smile.gif', '' => 'sad.gif', ); if(substr($this->smiley_url,-1) != '/' && !empty($this->smiley_url)) { $this->smiley_url .= '/'; } foreach($smilies as $code => $image) { $data = str_replace($code, "<img src='{$this->smiley_url}{$image}' alt='{$code}' />", $data); } return $data; } function _parse_censors($data) { global $badwords; $mask = "*"; for ($i = 0; $i < sizeof($words); $i++) { $censored = substr($badwords[$i], 0, 1); for ($x = 1; $x < strlen($badwords[$i]); $x++) $censored .= $mask; $data = str_replace($badwords[$i], $censored, $data); } return $data; } } ?> Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/73520-solved-building-an-array-with-mysql-results-then-parsing-them/ Share on other sites More sharing options...
sasa Posted October 16, 2007 Share Posted October 16, 2007 try to change line for ($i = 0; $i < sizeof($words); $i++) to for ($i = 0; $i < sizeof($badwords); $i++) Quote Link to comment https://forums.phpfreaks.com/topic/73520-solved-building-an-array-with-mysql-results-then-parsing-them/#findComment-370945 Share on other sites More sharing options...
scarhand Posted October 16, 2007 Author Share Posted October 16, 2007 thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/73520-solved-building-an-array-with-mysql-results-then-parsing-them/#findComment-371114 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.