AbydosGater Posted January 10, 2007 Share Posted January 10, 2007 Hey.. On my chatroom.. i have a function that will remove all html from a users post if they do not have high enough clearance and replaces code words with image tags for smilies.. and last it will replace newline \n with a <br>..[code]function modifyPost($message){$message = $message;$message = str_replace("\n", "<br>", $message);$message = str_replace("*angel*", "<img src=\'http://shadowfleet.info/smilies/angel.gif\' name=\'angel\'> ", $message);$message = str_replace("*clap*", "<img src=\'http://shadowfleet.info/smilies/clap.gif\' name=\'clap\'> ", $message);$message = str_replace("*drool*", "<img src=\'http://shadowfleet.info/smilies/drool.gif\' name=\'drool\'> ", $message);$message = str_replace("*evil", "<img src=\'http://shadowfleet.info/smilies/evil.gif\' name=\'evil\'> ", $message);$message = str_replace("GETOUT", "<img src=\'http://shadowfleet.info/smilies/getout.gif\' name=\'getout\'> ", $message);$message = str_replace("*love*", "<img src=\'http://shadowfleet.info/http://shadowfleet.info/smilies/love.gif\' name=\'love\'> ", $message);$message = str_replace("*moon*", "<img src=\'http://shadowfleet.info/smilies/moon.gif\' name=\'moon\'> ", $message);$message = str_replace(":O", "<img src=\'http://shadowfleet.info/smilies/ohh.gif\' name=\'ohh\'> ", $message);$message = str_replace("*no*", "<img src=\'http://shadowfleet.info/smilies/nono.gif\' name=\'nono\'> ", $message);$message = str_replace("*hallowed*", "<img src=\'http://shadowfleet.info/smilies/orihallowed.gif\' name=\'ori\'> ", $message);$message = str_replace("*prior*", "<img src=\'http://shadowfleet.info/smilies/prior.gif\' name=\'prior\'> ", $message);$message = str_replace("*poke*", "<img src=\'http://shadowfleet.info/smilies/shit.gif\' name=\'poke\'> ", $message);$message = str_replace("*shoot*", "<img src=\'http://shadowfleet.info/smilies/shoot.gif\' name=\'shoot\'> ", $message);$message = str_replace(":angel:", "<img src=\'http://shadowfleet.info/smilies/angel.gif\' name=\'angel\'> ", $message);$message = str_replace(":P", "<img src=\'http://shadowfleet.info/smilies/tounge.gif\' name=\':P\'> ", $message);$message = str_replace("*mates*", "<img src=\'http://shadowfleet.info/smilies/tralala.gif\' name=\'mates\'> ", $message);$message = str_replace(":toilet:", "<img src=\'http://shadowfleet.info/smilies/wc.gif\' name=\'wc\' id=\'wc\'> ", $message);$message = str_replace(":?", "<img src=\'http://shadowfleet.info/smilies/what.gif\' name=\'what\'> ", $message);$message = str_replace(":D", "<img src=\'http://shadowfleet.info/smilies/D.gif\' name=\'D\'> ", $message);if ($_SESSION['user']['CL'] < 3){---> $message = strip_tags($messsage, "<br><img>");};return $message;}[/code]But its not working.. the problem is within the line i have marked with an arrow within the final if statment.. but its not working for me.. its taking the message a user posts and its inserting nothing to the database.. i know its this line as everything works when i comment it out. it should remove all html except br and img tags.. I know thats what it will do if a user does have html in a message.. it will delete everything between the tags aswell.. but even when a user posts hello.. its comming up blank.. anyone see where i went wrong? i cant!-Andy Link to comment https://forums.phpfreaks.com/topic/33609-strip_tags-gone-wrong/ Share on other sites More sharing options...
obsidian Posted January 10, 2007 Share Posted January 10, 2007 Well, think about what you're doing. Not the actual functions, they're all fine, but the [b]order[/b] in which you call them. You have just gone through a large list of functions [i]creating[/i] HTML tags, and then you call strip_tags() [b]after[/b] that. You just need to run your strip_tags() function first, and then create all your BBCode type replacements. Link to comment https://forums.phpfreaks.com/topic/33609-strip_tags-gone-wrong/#findComment-157467 Share on other sites More sharing options...
AbydosGater Posted January 10, 2007 Author Share Posted January 10, 2007 Ok thanks.. So now ive put it at the top.. but now if there is html the message could be deleted and there could be a blank post added to the database.. so i added an if to check if the message is empty.. if it is it will call it message censored...[code]<?phpfunction modifyPost($message){$message = $message;if ($_SESSION['user']['CL'] < 3){$message = strip_tags($messsage);};$message = str_replace("\n", "<br>", $message);$message = str_replace("*angel*", "<img src=\'http://shadowfleet.info/smilies/angel.gif\' name=\'angel\'> ", $message);$message = str_replace("*clap*", "<img src=\'http://shadowfleet.info/smilies/clap.gif\' name=\'clap\'> ", $message);$message = str_replace("*drool*", "<img src=\'http://shadowfleet.info/smilies/drool.gif\' name=\'drool\'> ", $message);$message = str_replace("*evil", "<img src=\'http://shadowfleet.info/smilies/evil.gif\' name=\'evil\'> ", $message);$message = str_replace("GETOUT", "<img src=\'http://shadowfleet.info/smilies/getout.gif\' name=\'getout\'> ", $message);$message = str_replace("*love*", "<img src=\'http://shadowfleet.info/http://shadowfleet.info/smilies/love.gif\' name=\'love\'> ", $message);$message = str_replace("*moon*", "<img src=\'http://shadowfleet.info/smilies/moon.gif\' name=\'moon\'> ", $message);$message = str_replace(":O", "<img src=\'http://shadowfleet.info/smilies/ohh.gif\' name=\'ohh\'> ", $message);$message = str_replace("*no*", "<img src=\'http://shadowfleet.info/smilies/nono.gif\' name=\'nono\'> ", $message);$message = str_replace("*hallowed*", "<img src=\'http://shadowfleet.info/smilies/orihallowed.gif\' name=\'ori\'> ", $message);$message = str_replace("*prior*", "<img src=\'http://shadowfleet.info/smilies/prior.gif\' name=\'prior\'> ", $message);$message = str_replace("*poke*", "<img src=\'http://shadowfleet.info/smilies/shit.gif\' name=\'poke\'> ", $message);$message = str_replace("*shoot*", "<img src=\'http://shadowfleet.info/smilies/shoot.gif\' name=\'shoot\'> ", $message);$message = str_replace(":angel:", "<img src=\'http://shadowfleet.info/smilies/angel.gif\' name=\'angel\'> ", $message);$message = str_replace(":P", "<img src=\'http://shadowfleet.info/smilies/tounge.gif\' name=\':P\'> ", $message);$message = str_replace("*mates*", "<img src=\'http://shadowfleet.info/smilies/tralala.gif\' name=\'mates\'> ", $message);$message = str_replace(":toilet:", "<img src=\'http://shadowfleet.info/smilies/wc.gif\' name=\'wc\' id=\'wc\'> ", $message);$message = str_replace(":?", "<img src=\'http://shadowfleet.info/smilies/what.gif\' name=\'what\'> ", $message);$message = str_replace(":D", "<img src=\'http://shadowfleet.info/smilies/D.gif\' name=\'D\'> ", $message);if (!$message){$message = "<i>Message Censored</i>";}return $message;}?>[/code]But no still all messages for CL 1 and 2 are being "Message Censored" Link to comment https://forums.phpfreaks.com/topic/33609-strip_tags-gone-wrong/#findComment-157483 Share on other sites More sharing options...
AbydosGater Posted January 10, 2007 Author Share Posted January 10, 2007 -Bump Link to comment https://forums.phpfreaks.com/topic/33609-strip_tags-gone-wrong/#findComment-157718 Share on other sites More sharing options...
kenrbnsn Posted January 10, 2007 Share Posted January 10, 2007 I noticed a few minor problems with your code, including escaping the single quote inside the double quoted string. That is not necessary. And what's the line "$message = $message" at the start?Here's my modification of your code ... *** Untested ***[code]<?phpfunction modifyPost($message){ if ($_SESSION['user']['CL'] < 3) $message = strip_tags($messsage); $new = array('angel','clap','drool','evil','getout','love','moon','ohh','nono','orihallowed','prior','shit','shoot','angel', 'tounge','tralala','wc','what','D'); $old = array('*angel*','*clap*','*drool*','*evil','GETOUT','*love*','*moon*',':O','*no*','*hallowed*','*prior*','*poke*', '*shoot*',':angel:',':P','*mates*',':toilet:',':?',':D'); $message = str_replace("\n", "<br>", $message); foreach($old as $idx => $word) $message = str_replace($word,'<img src="http://shadowfleet.info/smilies/' . $new[$idx] . '.gif' alt="' . $new[$idx] . '"> ', $message); if (strlen($message) == 0) $message = "<i>Message Censored</i>"; return $message;}?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/33609-strip_tags-gone-wrong/#findComment-157740 Share on other sites More sharing options...
AbydosGater Posted January 11, 2007 Author Share Posted January 11, 2007 Hmm im getting an unexpected T_STRING from line 23 which is the $message = str_replace($word,'<img src="http://shadowfleet.info/smilies/' . $new[$idx] . '.gif' alt="' . $new[$idx] . '"> ', $message);Any idea? i cant see anything but im very tired.-Andy Link to comment https://forums.phpfreaks.com/topic/33609-strip_tags-gone-wrong/#findComment-158283 Share on other sites More sharing options...
obsidian Posted January 11, 2007 Share Posted January 11, 2007 Your quotes are off a bit. Here's what you have:[code]<?php$message = str_replace($word,'<img src="http://shadowfleet.info/smilies/' . $new[$idx] . '.gif' alt="' . $new[$idx] . '"> ', $message);?>[/code]Here's what it should be:[code]<?php$message = str_replace($word,'<img src="http://shadowfleet.info/smilies/' . $new[$idx] . '.gif" alt="' . $new[$idx] . '"> ', $message);?>[/code] Link to comment https://forums.phpfreaks.com/topic/33609-strip_tags-gone-wrong/#findComment-158287 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.