Jump to content

Need help stripping quoted text from phpbb post


Kyrillos

Recommended Posts

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]
Link to comment
Share on other sites

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 points

example 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
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.