View Full Version : Help with cleaner.php (REGEX)
The Dawg
06-29-2011, 04:12 PM
I need to replace an outdated mods text in posts.
Old code example:
YouTube - ‪Bill O'Reilly Interviews Rapper Lupe Fiasco - 06/20/11‬‏
How I want the new code to look:
http://www.youtube.com/watch?v=wYJ20INbM7Q
Regex I was given by a coder:
$text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', 'http://www.youtube.com/watch?v=$1', $text);
I do not know where to put this in cleaner.php :(:(:(
I put it here:
// BACK UP YOUR DATABASE
$replacer = array(
$text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i',
'http://www.youtube.com/watch?v=$1', $text)
);
// BACK UP YOUR DATABASE
and it does nothing.
Please tell me how to execute this code.
Thanks
BirdOPrey5
06-29-2011, 06:06 PM
What is cleaner.php? Where did you get it from?
The Dawg
06-29-2011, 06:14 PM
What is cleaner.php? Where did you get it from?
Cleaner.php is the impex/tools/ folder for Vbulletin.
BirdOPrey5
06-29-2011, 06:26 PM
I need to replace an outdated mods text in posts.
Old code example:
YouTube - ‪Bill O'Reilly Interviews Rapper Lupe Fiasco - 06/20/11‬‏
How I want the new code to look:
http://www.youtube.com/watch?v=wYJ20INbM7Q
Regex I was given by a coder:
$text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', 'http://www.youtube.com/watch?v=$1', $text);
I do not know where to put this in cleaner.php :(:(:(
I put it here:
// BACK UP YOUR DATABASE
$replacer = array(
$text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i',
'http://www.youtube.com/watch?v=$1', $text)
);
// BACK UP YOUR DATABASE
and it does nothing.
Please tell me how to execute this code.
Thanks
You find this in cleaner.php
#$text = preg_replace('##siU', '', $text);
Change it to this:
$text = preg_replace('#[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|#siU', 'http://www.youtube.com/watch?v=$1', $text);
Try that. Make sure you have a backup though, I couldn't test this.
The Dawg
06-29-2011, 07:17 PM
Got some progress. :up:
(I am running this on a test database to get the syntax right)
Cleaner ran but I got the error:
Warning: preg_replace(): Compilation failed: unmatched parentheses at offset 48
I looked at the test thread and it deleted the string I want to replace but it did not replace it ( due to the error )
So if I can get the code correct it should work.
--------------- Added 1309380139 at 1309380139 ---------------
Success!
Here is the regex pattern that worked:
$text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', 'http://www.youtube.com/watch?v=$1', $text);
BirdOPrey5
06-29-2011, 07:44 PM
I took another look at the code, I think there were a couple typos-
try this line:
$text = preg_replace('#\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)#siU', 'http://www.youtube.com/watch?v=$1', $text);
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.