BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 preg_replace() compares a pattern to a string and replaces that pattern with the provided replacement string. so you'll need to loop over the dis-allowed tags and use preg_replace, or build a crafty regular expression that does it in one shot. we'll stick to the easy version: $bad_tags = array("<BR>","<UL>","<WHATEVER>"); foreach ($bad_tags AS $a_bad_tag) { $pattern = "/^$a_bad_tag$/i"; // or something similar, i'm not regex pro... preg_replace($pattern, "<nocode>", $string); // Where $string is the content } echo $string; // replaced string. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 A pattern something like this: preg_replace('(<br>|<ol>)','<bad>',$badcodes); That will remove <br>, <Br>, <bR>, <BR> and <ol> (case insensitive) with <bad> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 don't we need /i in the pattern to denote case-insensitivity for preg_replace? examples here: http://us2.php.net/preg_replace Quote Link to comment Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 Probably yes, not on my usual machine and not got access to any of my source atm Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 Correct solution: str_ireplace (but I don't have PHP 5) My solution: strtolower(); (Although there are other methods this was easiest) Quote Link to comment Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 Just note that if the input from the user has any capitals (like a name) then it'll be returned with all lower case. Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 yea whatever, they aren't neccessary Quote Link to comment 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.