Help REGEX help with Vbulletin cleaner.php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The Dawg
    Confirmed User
    • Apr 2002
    • 2438

    #1

    Help REGEX help with Vbulletin cleaner.php

    I need to replace all of the mod code from an outdated youtube video embedding mod [ame] to [video].

    Old code:

    Code:
    [ame="http://www.youtube.com/watch?v=wYJ20INbM7Q"]YouTube - ‪Bill O'Reilly Interviews Rapper Lupe Fiasco - 06/20/11‬‏[/ame]
    I want the new code to look like this:

    Code:
    [video=youtube;wYJ20INbM7Q]http://www.youtube.com/watch?v=wYJ20INbM7Q[/video]
    Cleaner.php has this section to do the search and replace:

    Code:
    // BACK UP YOUR DATABASE
    $replacer = array(
                            ""      => "",
                            ""      => "",
                            ""      => "",
    );
    I want to add a $text = preg_replace with regex code to replace the old code.

    I got this from stackoverflow:

    $text = preg_replace('#\[ame\=".*?\=([a-zA-Z0-9]*?)"]#', '( )', $text);
    and

    Code:
    $text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\]|i', '[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]', $text);
    The code looks right, but neither affected the thread text.

    Anyone know how to make this work?

  • The Dawg
    Confirmed User
    • Apr 2002
    • 2438

    #2
    Bump for more eyes.

    Comment

    • fris
      I have to go potty
      • Aug 2002
      • 55730

      #3
      why not just create a new custom bb code, or are you trying to replace all the current ones via the database?
      Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

      My Latest Theme

      Comment

      • V_RocKs
        Damn Right I Kiss Ass!
        • Nov 2003
        • 32448

        #4
        I believe it is a problem that has more to do with where you are putting the code. I added a small piece to the code to remove the other shit at the end:

        Here is the code from my example.. You can drop it into a php extension file and run it on your sever to see the output and play with it yourself...

        Code:
        <?
        
        $text = '[ame="http://www.youtube.com/watch?v=wYJ20INbM7Q"]YouTube - &#x202a;Bill O\'Reilly Interviews Rapper Lupe Fiasco - 06/20/11&#x202c;&rlm;[/ame]';
        
        $text3 = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', '[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]', $text);
        
        
        echo "$text <br><br>$text3";
        
        $text5 = '[video=youtube;wYJ20INbM7Q]http://www.youtube.com/watch?v=wYJ20INbM7Q[/video]';
        echo "<br><br>$text5";
        
        ?>
        And the output is:

        [ame="http://www.youtube.com/watch?v=wYJ20INbM7Q"]YouTube - ‪Bill O'Reilly Interviews Rapper Lupe Fiasco - 06/20/11‬‏[/ame]





        Which is:

        line 1 - original string
        line 2 - modified string
        line 3 - what you wanted.

        Notice 2 and 3 match.

        Comment

        • V_RocKs
          Damn Right I Kiss Ass!
          • Nov 2003
          • 32448

          #5
          Of course you could just run this on the DB as Fris suggested and be done with it.

          Comment

          • The Dawg
            Confirmed User
            • Apr 2002
            • 2438

            #6
            Originally posted by fris
            why not just create a new custom bb code, or are you trying to replace all the current ones via the database?
            Yes this is to replace the current ones in the database.
            Originally posted by V_RocKs
            I believe it is a problem that has more to do with where you are putting the code. I added a small piece to the code to remove the other shit at the end:

            Here is the code from my example.. You can drop it into a php extension file and run it on your sever to see the output and play with it yourself...

            Code:
            <?
            
            $text = '[ame="http://www.youtube.com/watch?v=wYJ20INbM7Q"]YouTube - &#x202a;Bill O\'Reilly Interviews Rapper Lupe Fiasco - 06/20/11&#x202c;&rlm;[/ame]';
            
            $text3 = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', '[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]', $text);
            
            
            echo "$text <br><br>$text3";
            
            $text5 = '[video=youtube;wYJ20INbM7Q]http://www.youtube.com/watch?v=wYJ20INbM7Q[/video]';
            echo "<br><br>$text5";
            
            ?>
            And the output is:

            [ame="http://www.youtube.com/watch?v=wYJ20INbM7Q"]YouTube - ‪Bill O'Reilly Interviews Rapper Lupe Fiasco - 06/20/11‬‏[/ame]





            Which is:

            line 1 - original string
            line 2 - modified string
            line 3 - what you wanted.

            Notice 2 and 3 match.
            Thanks. I have a test database that I am running the test configurations on before I mess with the live forum. 2.5Million posts... so I cant screw it up.

            Comment

            • V_RocKs
              Damn Right I Kiss Ass!
              • Nov 2003
              • 32448

              #7
              this won't make changes to the DB... so far as I know... didn't see what you were using to do that.

              Comment

              • The Dawg
                Confirmed User
                • Apr 2002
                • 2438

                #8
                Originally posted by V_RocKs
                this won't make changes to the DB... so far as I know... didn't see what you were using to do that.
                Your the man!

                I just plugged in the code:

                Code:
                $text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', '[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]', $text);
                It processed correctly! Thanks a lot!

                Comment

                Working...