vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Help with cleaner.php (REGEX) (https://vborg.vbsupport.ru/showthread.php?t=265984)

The Dawg 06-29-2011 04:12 PM

Help with cleaner.php (REGEX)
 
I need to replace an outdated mods text in posts.

Old code example:
Code:

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

Code:

[video=youtube;wYJ20INbM7Q]http://www.youtube.com/watch?v=wYJ20INbM7Q[/video]
Regex I was given by a coder:

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);
I do not know where to put this in cleaner.php :(:(:(

I put it here:

PHP Code:

// BACK UP YOUR DATABASE
$replacer = array(
$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
);

// 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

Quote:

Originally Posted by BirdOPrey5 (Post 2214671)
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

Quote:

Originally Posted by The Dawg (Post 2214617)
I need to replace an outdated mods text in posts.

Old code example:
Code:

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

Code:

[video=youtube;wYJ20INbM7Q]http://www.youtube.com/watch?v=wYJ20INbM7Q[/video]
Regex I was given by a coder:

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);
I do not know where to put this in cleaner.php :(:(:(

I put it here:

PHP Code:

// BACK UP YOUR DATABASE
$replacer = array(
$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
);

// BACK UP YOUR DATABASE 

and it does nothing.

Please tell me how to execute this code.

Thanks


You find this in cleaner.php

PHP Code:

        #$text = preg_replace('##siU', '', $text); 

Change it to this:
PHP Code:

        $text preg_replace('#[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|#siU''[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]'$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 [DATE]1309380139[/DATE] at [TIME]1309380139[/TIME] ---------------

Success!

Here is the regex pattern that worked:

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);

BirdOPrey5 06-29-2011 07:44 PM

I took another look at the code, I think there were a couple typos-

try this line:

Code:

    $text = preg_replace('#\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)#siU', '[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]', $text);


All times are GMT. The time now is 03:19 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01141 seconds
  • Memory Usage 1,732KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_code_printable
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete