vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   using preg_replace to turn one BB Code into another BB Code... (https://vborg.vbsupport.ru/showthread.php?t=255931)

BirdOPrey5 12-26-2010 08:02 PM

using preg_replace to turn one BB Code into another BB Code...
 
What I need to do is when a message is quoted to replace one bb code inside the quote with another bb code...

So let's say the message data contains:
Code:

[quote=BirOPrey;938322]This is a test [cust]http://www.google.com[/cust] more test. One more time  [cust]http://www.yahoo.com[/cust][/quote]

Hi. [cust]http://www.bing.com[/cust]
Bye.

I would want it to change to:
Code:

[quote=BirOPrey;938322]This is a test [xxx]http://www.google.com[/xxx] more test. One more time  [xxx]http://www.yahoo.com[/xxx][/quote]

Hi. [cust]http://www.bing.com[/cust]
Bye.

The hooks and variables I'm sure I can figure out... and I've been pretty good making regular expressions with regex buddy these days...

I'm thinking preg_replace will be the key to doing this... to match [cust] and [/cust] and replace with [xxx] and [/xxx] only within a quote- but I have read the pho manual on preg_replace and wondering if there isn't more to it?

I found some info in this thread: https://vborg.vbsupport.ru/showthread.php?t=77173
But that code doesn't seem to work in 3.7/3.8...

EDIT

That line from that thread looks exactly like I want to do.., in class_bbcode.php after line 1424 I want to do a preg_replace on $html and change all the [cust] tags to [xxx] but this is never matching:
Code:

$html = preg_replace('#\[test\]\s*(https?://([^<>*"]+|[a-z0-9/\\._\- !]+))\[/test\]#iue', "[url]$1[/url]", $html);
Trying to change [test] to [ url ] in that example...

Edit AGAIN
It appears the problem is in 3.8 $html and $message are already converted to HTML so there are no bb code's left in the code at this point anymore, they have already been parsed.

--------------- Added [DATE]1293416282[/DATE] at [TIME]1293416282[/TIME] ---------------

Well I ended up just using str_replace, twice... Once to remove all the HTML in front of the {param} and replace it, and another to remove and replace all the code after the {param}... I was looking and I just don't see anywhere were the unparsed QUOTE only is available...

--------------- Added [DATE]1293417599[/DATE] at [TIME]1293417599[/TIME] ---------------

Wow... I found a mod that does everything I need really easily... at least this was a learning experience...

https://vborg.vbsupport.ru/showthread.php?t=191223 :up:

Jaffery 12-28-2010 08:00 AM

Btw, there is cleaner.php found under /impex/tools which lets you convert things and replaces variable in posts. Hope you didn't missed that as I had once converted various bb code into other formats.

BirdOPrey5 12-28-2010 01:10 PM

Thanks for the info. :up:


All times are GMT. The time now is 01:02 AM.

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.00984 seconds
  • Memory Usage 1,718KB
  • 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
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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