quickstream Posted November 2, 2007 Share Posted November 2, 2007 ok im working with subdreamer and installed a mod which interacts with a forum on my host so that news is shown on the front page, but i have a 20word limit so the bbcode is usually cut short which in turn messeges the whole row of news up (beyond the one article it is in) soo i have tried to remove it i can eaily deactive the bbcode but i cannot remove the tags thus i introduce this code $no_bbcode = explode(bbencode_second_pass($post['message'], $post['bbcode_uid'])); foreach ($no_bbcode as $nobbcode) { $post['message'] = eregi_replace($nobbcode, "", $post['message']); } i have tried a few variations of this including $no_bbcode = explode($post['bbcode_uid']); foreach ($no_bbcode as $nobbcode) { $post['message'] = eregi_replace($nobbcode, "", $post['message']); } & $no_bbcode = explode('|','[b]|[/b]|[i]|[/i]|[u]|[/u]|[quote]|[/quote]|[code]| ||]|[list=]| |'); foreach ($no_bbcode as $nobbcode) { $post['message'] = eregi_replace($nobbcode, "", $post['message']); } [/code] non work as they should, i would have tried something like mysql_escape_string() but that wont effect bbcode will it? lil help please im non a very good php code junky and im stil teaching myself but im genuinly stuck Quote Link to comment Share on other sites More sharing options...
quickstream Posted November 3, 2007 Author Share Posted November 3, 2007 sorry to bump but im in need of help Quote Link to comment Share on other sites More sharing options...
Daukan Posted November 3, 2007 Share Posted November 3, 2007 I'm not great with regular expression but here goes. $post['message'] = preg_replace('@\[[\/\!]*?[^\[\]]*?\]@si', '', $post['message']); Quote Link to comment Share on other sites More sharing options...
quickstream Posted November 3, 2007 Author Share Posted November 3, 2007 I'm not great with regular expression but here goes. $post['message'] = preg_replace('@\[[\/\!]*?[^\[\]]*?\]@si', '', $post['message']); soo $post['message'] = preg_replace('[b], [/b], [i], [/i], etc?', '', $post['message']); yes?, il try now but its a whole lot more simpler then my version, though i may add a new expression after this format has taken place so i can add a function in the admin panel to turn it on and off Quote Link to comment Share on other sites More sharing options...
Daukan Posted November 3, 2007 Share Posted November 3, 2007 The one posted removes all matches of [] and [/ ] and anything contained within. If you need more control over it try it this way <?php $search = array ( '@([b])@i', // remove bold start '@([/b[)@i', // remove bold end '@([i])@i', // remove italics start '@([/i])@i', // remove italics end '@([u])@i', '@([/u])@i', '@([quote])@i', '@([/quote])@i' ); $replace = array ('', '', '', '', '', '', '', ''); $post['message'] = preg_replace($search, $replace, $post['message']); ?> Add as many as you want just keep the two arrays balanced, but it seems simpler to remove them all at once... Quote Link to comment Share on other sites More sharing options...
quickstream Posted November 3, 2007 Author Share Posted November 3, 2007 ok both code lines work the problem is with what im trying to exclude, the square brackets may be having a problem right in the code? is there a strip_something() varible i can use? which has been brought up in the new post, so il try that code it looks very interesting and iv only just gone past that chapter in the book im reading to get a grasp of php keke il let you know of the result if positive il resolve this thread Quote Link to comment Share on other sites More sharing options...
marcus Posted November 3, 2007 Share Posted November 3, 2007 That won't work silly. $codes = array('your','bbcode','here'); foreach($codes AS $code){ $_POST['message'] = preg_replace($code, NULL, $_POST['message']); } Quote Link to comment Share on other sites More sharing options...
quickstream Posted November 3, 2007 Author Share Posted November 3, 2007 iv got time to try more then one if it wont work then fine but he made the time to post so il make the time to try it Quote Link to comment Share on other sites More sharing options...
quickstream Posted November 3, 2007 Author Share Posted November 3, 2007 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/suddende/public_html/plugins/p407_forum_news/phpbb.php on line 129 Quote Link to comment Share on other sites More sharing options...
quickstream Posted November 3, 2007 Author Share Posted November 3, 2007 non of these work without some kind of unwanted effect after a second try the array does the best it only leave the bbcode id but also had a side effect which pretty much makes all the messege spam such as "gfhjkdfshjkfhds", i can remove bbcode id and here is the unwanted effect its not made it spam just removed the letters and spaces Quote Link to comment Share on other sites More sharing options...
Daukan Posted November 3, 2007 Share Posted November 3, 2007 I'm not sure what you are looking for. It removes the bbcode for me. <?php $_POST['message'] = '[b]Hello, [/b][i]hello, [/i][u]goodbye[/u]'; $_POST['message'] = preg_replace('@\[[\/\!]*?[^\[\]]*?\]@si', '', $_POST['message']); echo htmlentities($_POST['message']); ?> displays-> Hello, hello, goodbye Quote Link to comment Share on other sites More sharing options...
quickstream Posted November 3, 2007 Author Share Posted November 3, 2007 look at screenshot and for some reason your code dnt work i can try again with it, but all i simple want is the just the tags gone, and disbaling the code is simple but removing the tags is harder 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.