phpSensei Posted August 31, 2007 Share Posted August 31, 2007 Alright, I don't know if this is possible, but the results always come out blank for me... $string = "One And Two And <b>string</b>"; $replace=array("/one/","/two/","'#<([^>]+)>(.*?)</\1>#'"); $with= array("1","2","[b]$2[/b]"); $reg=preg_replace($replace,$with,$string); I want to filter bad words, and I also want to convert string to at the same time. I know the regex, and I know how to change the bbcode to what I want, but I don't know if this is possible.... Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 alright, I noticed this is sort of regex, maybe a moderator can move it? Quote Link to comment Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 The patterns for "One" and "Two" need to be case insensitive, and your last pattern does not need 2 sets of quotes. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 what if I added preg_replace("","<b>",$string); it never comes out right... it make the text bold, and prints out "//"and"[]"... Quote Link to comment Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 <pre> <?php $string = "One And Two And <b>string</b>"; $replace=array("/one/i","/two/i",'#<([^>]+)>(.*?)</\1>#'); $with= array("1","2",'[b]$2[/b]'); echo $reg=preg_replace($replace,$with,$string); ?> </pre> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 SWEARING IN HERE replace = array('/fuck/', '/cock/', '/shit/', '/ass/','/bitch/','/motherfucker/','/pussy/','/fucking/','/whore/' ,'/\[b\](.*?)\[\/b\]/','/\[i\](.*?)\[\/i\]/is','/\[u\](.*?)\[\/u\]/is' ); $with = array('f***', 'c***', 's***', 'a**','b****','motherf******','p****','f***ing','wh***','<strong>$1</strong>','<em>$1</em>', '<u>$1</u>' ); $message=strip_tags($row['message']); $message = preg_replace($replace, $with, $message); $message=stripslashes($message); thanks, i managed to get it working, and with your help Quote Link to comment Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 That would change "harass" into "hara**", and that's only one example. You might want to invest in some word boundaries. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 what should I put instead... I am terrible at regex.. Quote Link to comment Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 Did you not look at the link? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 preg_replace("\bitch\b","b****",$string) am I right? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 nvm, it didnt work. I will read more... Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 like this? /\bass/ Quote Link to comment Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 From the first paragraph after the list: Simply put: \b allows you to perform a "whole words only" search using a regular expression in the form of \bword\b. Notice how there is a \b on each side. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 http://localhost/forum_software/index.php?page=viewtopic&forum=2&topic=17 I did this /\bass/ Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 sorry, wrong link.. i thought i was on my site. Quote Link to comment Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 /\bass/ will fix the "harass" problem, but it will turn "assessment" into "a**essment" Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 so I will need one for each side like you said.... Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 when you do this ass it wont filter the word. 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.