The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
text replacements help
I have this code below...but I also want to have multiple replacements. Like {userid} for example. How can I add multiple replacements to this line of code?
Code:
$test = @str_replace("{username}", $vbulletin->userinfo['username'], $message); Code:
$test = @str_replace("{username}", $vbulletin->userinfo['username'], $message); $test = @str_replace("{userid}", $vbulletin->userinfo['userid'], $message); but it didnt work, and still only outputted the userid and not both |
#2
|
||||
|
||||
Because you use $message in the second source string. Use $test there.
PHP Code:
|
#3
|
||||
|
||||
and what if I wanna add a third and fourth, how does the theory apply? New variables each time? Because I wanna be able to use multiple replacements like username, userid, all in the same variable...from the text field I made up in the product options, I made.
You've gotta be able to do it all in one line...(peice of code) |
#4
|
||||
|
||||
No, I'll try to explain better.
The main text is held in the variable $message. We create a new variable called $test, which is equal to $message, just with the replaced words. So we want to replace more words, we'll use the $test variable as third argument in str_replace() as $test contains the variables we replaced first. We want these plus the ones we're gonna replace now. Do you understand? $message remains untouched as we assign the NEW text to a different variable. So use this new variable for the other replacements too. PHP Code:
Another option is using arrays as arguments. PHP Code:
|
#5
|
||||
|
||||
Nico, that makes alot more sense, I really appreciate the explaination and code examples. It works! Thanks again.
One more issue...how can I retrieve the logged in users usergroup title? The below wont work at all...nor will other combinations I've tried... PHP Code:
|
#6
|
||||
|
||||
vBulletin has a built-in function to do this. Just use {1}, {2}, and so-forth as the replacement.
http://members.vbulletin.com/api/vBu...nstruct_phrase |
#7
|
||||
|
||||
Well, what I have is working fine...just cant grab the usergroups title, which may be a seperate issue. Maybe I'll have to do a query or something
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|