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.... Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/ 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? Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338785 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. Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338808 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"[]"... Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338810 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> Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338813 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 Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338829 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. Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338834 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.. Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338849 Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 Did you not look at the link? Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338854 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? Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338861 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... Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338865 Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Author Share Posted August 31, 2007 like this? /\bass/ Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338867 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. Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338869 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/ Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338870 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. Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338872 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" Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338880 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.... Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338884 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. Link to comment https://forums.phpfreaks.com/topic/67483-php-combining-regex/#findComment-338889 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.