Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 05-08-2012, 06:29 PM
Chris8's Avatar
Chris8 Chris8 is offline
 
Join Date: Nov 2009
Posts: 188
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Php coding question

I'm messing with bbcodes and I have a little problem here.
What will be output of this:

Code:
preg_replace('/\{option(\d+)\}/e', "'%' . (intval('\\1')+1) . '\$s'", $bbcode['html']);
It supposed to replace {option1} {option2} {option3} and so on but to what exactly?

The default {option} is replaced with %2$s the above must have something in common with %2$s but I'm not sure how it's transformed.

Please help me to resolve this problem.
Reply With Quote
  #2  
Old 05-08-2012, 06:38 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The matched text that corresponds to parts of the pattern enclosed in parens can be used in the replacement as \1 for the first set of parens, \2 for the second, etc. So the (\d+) in the pattern matches a string of one or more digits (i.e. an integer), and it's used in the replacement as '\\1' (why it needs an extra backslash is another story - it might be best if you look at this page for the description of the 'e' modifier http://www.php.net/manual/en/referen....modifiers.php).


Edit: reading your post again, maybe I misunderstood? I don't know why {option} would be matched at all by that pattern.
Reply With Quote
  #3  
Old 05-09-2012, 03:45 PM
Chris8's Avatar
Chris8 Chris8 is offline
 
Join Date: Nov 2009
Posts: 188
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I still don't understand. ^^' Yeah, it's not going to match but to replace {option1} {option2} and so on with something and I'm looking for to get to know what is this something. I'm almost sure it is %2$s with appended number, what I'm not sure is how the numbers are appended. For example would it be %3$s, %4$s etc? Probably no, %21$s %23$s ? or maybe %2+1$s, %2+2$s? I'm not a coder so it's difficult for me to interpret this. The question is what will be {option1} {option2} {option3} and so on transformed to after the replacement.

Hire is the whole code:

PHP Code:
!$this->is_wysiwyg())
{
    foreach (
$this->tag_list['option'] AS $tag => $bbcode)
    {
        if (
strpos($bbcode['html'], '{option1}') !== false)
        {
            unset(
$this->tag_list['option']["$tag"]['html']);
            
$this->tag_list['option']["$tag"]['replace'] = preg_replace('/\{option(\d+)\}/e'"'%' . (intval('\\1')+1) . '\$s'"$bbcode['html']);
            
$this->tag_list['option']["$tag"]['callback'] = 'handle_external';
            
$this->tag_list['option']["$tag"]['external_callback'] = 'handle_bbcode_multioption';
        }
    }

Reply With Quote
  #4  
Old 05-09-2012, 03:50 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It looks to me like {option0} is replaced by %1$s, {option1} by %2$s, etc.
Reply With Quote
  #5  
Old 05-09-2012, 07:10 PM
Chris8's Avatar
Chris8 Chris8 is offline
 
Join Date: Nov 2009
Posts: 188
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I got it working. I've used plain {optionx} instead of %3$s %4$s etc,
when I try to replace it with variables like: %3$s %4$s, nothing is displaying when I test it in production, only %2$s seems to work but it displays all options together and duplicates them.

Thank you for trying anyway, I appreciate it.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05020 seconds
  • Memory Usage 2,201KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete