The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Getting variables from a string
Let's say I have a string that contains "This has a $var1 and $var2" (ignore escaping the $ for now). How can I find out what variable namess are in the string? I'm defining a variable name as everything from the leading $ to an illegal variable name character, including array braces ([]).
I know it probably involves regular expressions but I don't know anything about them. |
#2
|
|||
|
|||
Well after reading the docs they happened to have a regex string defining a variable, so I wrote this (ignore the junk about removing the $s):
PHP Code:
|
#3
|
||||
|
||||
hmm, don't exactly know if it would work correctly, have you tried with $$vars ?
i think the expand function could also help you here.... |
#4
|
|||
|
|||
Any examples? A slightly modified version of the above seems to be working fine for me...
|
#5
|
||||
|
||||
sorry, meant strtok function....
PHP Code:
|
#6
|
|||
|
|||
Problem is that could return just any things beginning with $. For example, it should work with a function like "$variable['index']" and return "$variable"
I'm pretty sure that the regex one is working so unless there's a more efficient way I think I'll keep that |
#7
|
||||
|
||||
a sorry, you are right then, your first sentence with including [] could be misunderstood (as i have done )
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|