![]() |
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); but it didnt work, and still only outputted the userid and not both |
Because you use $message in the second source string. Use $test there.
PHP Code:
|
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) |
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:
|
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:
|
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 |
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
|
All times are GMT. The time now is 02:35 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 | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|