Kyrillos Posted January 4, 2007 Share Posted January 4, 2007 alright well what ive been trying to in this php script is strip the bbcode off a message which i did successfully, and now im trying to strip the quote bbcode aswell as the quoted text, and only leave the rest of the message, so far ive been unsuccessful with the quoted message, but i have removed the quote bbcode please help i desperately need it. I am a tcl coder and a barely got this together so i do not know much about php or regex, if you could please provide the fix for me i would be greatful. If you are unable to provide me with a fix to it please tell me how i could go about doing this.NOTE: THERE ARE SOME TCL COLOR CODES IN HERE, BECAUSE THIS SCRIPT RELAYS THE DATA TO AN IRC EGGDROP SO PLEASE IGNORE THE COLOR CODES eg: /00309,01[code]<?php$bb2egg['channel'] = "#zex";$bb2egg['ids'] = "9 20 21 22 23 24 19"; $bb2egg['botip'] = "61.22.33.60";$bb2egg['botport'] = "1337";$bb2egg['boardurl'] = "http://teamzex.net/forum";$bb2egg['pass'] = "password";function send2egg($mode, $forumid, $topic_id, $user_id, $subject, $message, $poll_title, $forum_name, $post_id){ global $userdata, $bb2egg; if ( check_id($forumid) == 0 ) { return; } $nick = $userdata['username']; $message = preg_replace("#\[(.*?)]#si", "", $message); $message = str_replace('<br />', "\n", $message); $message = str_replace('<center>', "", $message); $message = str_replace("\n", "", $message); $message = preg_replace('/\[quote="(.*?)"](.*?)quote]/','',$message); if (strlen($message) > 50) { $text = substr($message,0,50)."..."; }else { $text = $message; } switch( $mode ) { case 'newtopic': if ( $poll_title != '' ) { $text2 = "\00309,01\002[»]\00314,01\002 New Poll Started By:\00300,01\002 $nick\00314,01\002 in\00300,01\002 $forum_name \00309,01[«]\002<br>"; } else { $text2 = "\00309,01\002[»]\00314,01\002 New Topic Posted By: \00300,01\002 $nick \00309,01[«]\002<br>"; } break; case 'reply': $text2 = "\002\00309,01[»]\00314,01\002 New Reply Posted By:\00300,01\002 $nick \00309,01[«]\002<br>"; break; default: break; } if ( $subject != '' ) { $text2 .= "\002\00309,01[»]\002 \00314,01Subject:\002\00300,01 $subject \00309,01[«]\002 <br>"; $text2 .= "\002\00309,01[»]\002 \00314,01Message:\002\00300,01 $text \00309,01[«]\002 <br>"; } else { $text2 .= "\002\00309,01[»]\002 \00314,01Message:\002\00300,01 $text \00309,01[«]\002<br>"; } $text2 .= "\002\00309,01[»]\002 \00314,01Link:\00300,01\002 \00300,01" . $bb2egg['boardurl'] . "/viewtopic.php?t=$topic_id#$post_id \00309,01[«]\002"; if ( $message == "" ) { $text2 = ""; } phpbb2egg($text2);}function phpbb2egg($text){global $bb2egg; if ( $text == '') { return; } $text = ereg_replace(";", ":", $text); $text = ereg_replace("<br>", ";", $text); $fp = fsockopen($bb2egg['botip'], $bb2egg['botport'], $errno, $errstr, 30); if ($fp) { fputs($fp, md5($bb2egg['pass']) ." ". $bb2egg['channel'] ." $text\n"); sleep(2); fclose($fp); }}function check_id($current){global $bb2egg; $forumids=explode(" ", $bb2egg['ids']); while ( list($n, $id) = each($forumids)) { if ($id == $current) { return 1; } } return 0;}?>[/code] Quote Link to comment Share on other sites More sharing options...
c4onastick Posted January 4, 2007 Share Posted January 4, 2007 Please post an example of $text, including what it looks like now and what you want it to look like. From looking at that, I have no idea what (or where) the problem is. We'd be glad to help, we just need a little more to go on. Quote Link to comment Share on other sites More sharing options...
Kyrillos Posted January 4, 2007 Author Share Posted January 4, 2007 This is an example of text b4:Yes i agree with this: (quote="dolven")Please post any feature articles you guys would like to see in the future and we will do our best to get them out!(/quote) He clearly states all of his pointsexample of text after:Yes i agree with this: He clearly states all of his points[i][b]Thank you again so much for your help, i really appreciate it[/b][/i]Please replace the () with [] i didnt. I didnt put them in brackets because of the BBcode it renders the actual quote Quote Link to comment Share on other sites More sharing options...
c4onastick Posted January 4, 2007 Share Posted January 4, 2007 Ok! Now the problem is coming into focus! There's two ways to do this: the Lamborghini way, and the Ferrari way.Here's your example string:[code]$old_code = 'Yes i agree with this: (quote="dolven")Please post any feature articles you guys would like to see in the future and we will do our best to get them out!(/quote) He clearly states all of his points';[/code]The Lamborghini way (brute force! More Power!), replace all instances of '()' with '[]'. (This may get you into trouble if there's embedded parens, which there might very well be). [code]$new_code = preg_replace('/\(([^)]+)\)/s', '[\1]', $old_code);[/code]This will match balanced sets of parens, and replace them with [].The Ferrari way (precision, poise, etc... whatever else is on the back of their pamphlet), is to strategically match the 'TAG', '/TAG' nature of these.[code]$new_code = preg_replace('/\(((\w+\b)[^)]*)\)(.*?)\(\/\2\)/s', '[\1]\3[/\2]', $old_code);[/code] Both ways produce the desired result with your test string. I'd use the Ferrari method, its more robust. It shouldn't match lone sets of parenthesizes. (I didn't test that, but I'd bet money it doesn't)Gets ugly quick, I know. But that hopefully should get you started! Enjoy! Quote Link to comment Share on other sites More sharing options...
Kyrillos Posted January 5, 2007 Author Share Posted January 5, 2007 uh c4onastick i that really wasnt the fix i needed, like what i needed wast to take out [quote"name"] quoted text here [/quote] and leave everything before and after it. Your code that you gave me doesnt really do that. Can you please give me another fix? Quote Link to comment Share on other sites More sharing options...
c4onastick Posted January 5, 2007 Share Posted January 5, 2007 Oh, so you want to completely remove any '(quote...)text text text (/quote)' constructs. That's simple enough.[code]$new_code = preg_replace('/\[(?:(\w+\b)[^)]*)\].*?\[\/\1\]/s', '', $old_code);[/code] Quote Link to comment Share on other sites More sharing options...
Kyrillos Posted January 5, 2007 Author Share Posted January 5, 2007 do you have AIM or MSN so that we can chat? Quote Link to comment Share on other sites More sharing options...
c4onastick Posted January 5, 2007 Share Posted January 5, 2007 Actually no. Sorry! 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.