GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Help REGEX help with Vbulletin cleaner.php (https://gfy.com/showthread.php?t=1028269)

The Dawg 06-28-2011 01:41 PM

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="https://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]https://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:

Quote:

$text = preg_replace('#\[ame\=".*?\=([a-zA-Z0-9]*?)"]#', '([video=youtube;$1]https://youtube.com/watch?v=$1[/video])', $text);
and

Code:

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

Anyone know how to make this work?

:helpme

The Dawg 06-28-2011 05:01 PM

Bump for more eyes.

fris 06-28-2011 05:52 PM

why not just create a new custom bb code, or are you trying to replace all the current ones via the database?

V_RocKs 06-28-2011 06:00 PM

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="https://youtube.com/watch?v=wYJ20INbM7Q"]YouTube - &#x202a;Bill O\'Reilly Interviews Rapper Lupe Fiasco - 06/20/11&#x202c;&rlm;[/ame]';

$text3 = preg_replace('|\[ame="https://youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', '[video=youtube;$1]https://youtube.com/watch?v=$1[/video]', $text);


echo "$text <br><br>$text3";

$text5 = '[video=youtube;wYJ20INbM7Q]https://youtube.com/watch?v=wYJ20INbM7Q[/video]';
echo "<br><br>$text5";

?>

And the output is:

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

[video=youtube;wYJ20INbM7Q]https://youtube.com/watch?v=wYJ20INbM7Q[/video]

[video=youtube;wYJ20INbM7Q]https://youtube.com/watch?v=wYJ20INbM7Q[/video]

Which is:

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

Notice 2 and 3 match.

V_RocKs 06-28-2011 06:01 PM

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

The Dawg 06-28-2011 09:06 PM

Quote:

Originally Posted by fris (Post 18246608)
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.
Quote:

Originally Posted by V_RocKs (Post 18246621)
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="https://youtube.com/watch?v=wYJ20INbM7Q"]YouTube - &#x202a;Bill O\'Reilly Interviews Rapper Lupe Fiasco - 06/20/11&#x202c;&rlm;[/ame]';

$text3 = preg_replace('|\[ame="https://youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', '[video=youtube;$1]https://youtube.com/watch?v=$1[/video]', $text);


echo "$text <br><br>$text3";

$text5 = '[video=youtube;wYJ20INbM7Q]https://youtube.com/watch?v=wYJ20INbM7Q[/video]';
echo "<br><br>$text5";

?>

And the output is:

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

[video=youtube;wYJ20INbM7Q]https://youtube.com/watch?v=wYJ20INbM7Q[/video]

[video=youtube;wYJ20INbM7Q]https://youtube.com/watch?v=wYJ20INbM7Q[/video]

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. :1orglaugh

V_RocKs 06-28-2011 11:50 PM

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

The Dawg 06-29-2011 01:41 PM

Quote:

Originally Posted by V_RocKs (Post 18247084)
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="https://youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', '[video=youtube;$1]https://youtube.com/watch?v=$1[/video]', $text);
It processed correctly! Thanks a lot!


All times are GMT -7. The time now is 07:01 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123