I have a PHP file with PHP Variables inside.
Example:
Hi =$username?>,
Can you please send me an email ?
I would like to
function extract_variables($content, $include_comments = false)
{
$variables = [];
if($include_comments)
{
preg_match_all('/\$[A-Za-z0-9_]+/', $content, $variables_);
foreach($variables_[0] as $variable_)
if(!in_array($variable_, $variables))
$variables[] = $variable_;
}
else
{
$variables_ = array_filter
(
token_get_all($content),
function($t) { return $t[0] == T_VARIABLE; }
);
foreach($variables_ as $variable_)
if(!in_array($variable_[1], $variables))
$variables[] = $variable_[1];
}
unset($variables_);
return $variables;
}
// --------------
$content = file_get_contents("file.php");
$variables = extract_variables($content);
print_r($vars[0]);
// --------------