The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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']); 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. |
#2
|
|||
|
|||
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. |
#3
|
||||
|
||||
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:
|
#4
|
|||
|
|||
It looks to me like {option0} is replaced by %1$s, {option1} by %2$s, etc.
|
#5
|
||||
|
||||
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. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|