Variable inside string
Lets say I have a string "My name is $name and my pet is $animal"
How to check if string has variables inside it? And if has, add to array like
$array = ("$name","animal");
Would it be some pregmatch? but then all $+sometextafterthesymbol needs to be extracted and $ with space after it left alone. Any ideas?
You can use regular expressions for this. The following will match any dollar sign followed by 1 or more word characters (letters, numbers, or underscore):
preg_match_all('/\$(\w+)/', $string, $matches);
Array (  => Array (  => $name  => $animal )  => Array (  => name  => animal ) )
Remember that $string, if hardcoded, must be wrapped in single quotes (').