如何列出文件中的所有PHP变量? [英] How to list all PHP variables in a file?

查看:104
本文介绍了如何列出文件中的所有PHP变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ p

  

我有一个包含PHP变量的PHP文件。 >嗨<?= $ username?>,
您能否给我发一封电子邮件?

我想从外部文件列出此文件中的每个PHP变量。

会返回的东西:

 数组(
'username'
);

我知道有一个名为的函数get_defined_vars ,但是这是一个外部文件。

是否有办法从外部文件获取所有PHP变量?



谢谢使用 file_get_contents() preg_match_all()可以使用

解决方案

  $ file = file_get_contents('file.php'); 
preg_match_all('/ \ $ [A-Za-z0-9 -_] + /',$ file,$ vars);

print_r($ vars [0]);


I have a PHP file with PHP Variables inside.
Example:

Hi <?=$username?>,
Can you please send me an email ?

I would like to list from an outside file, every PHP variables in this file.
Something that would return:

Array(
   'username'
);

I know there is a PHP function called get_defined_vars, but this is an external file.
Is there a way to get all PHP vars from an external file ?

Thank you

解决方案

Use file_get_contents() and preg_match_all():

$file = file_get_contents('file.php'); 
preg_match_all('/\$[A-Za-z0-9-_]+/', $file, $vars);

print_r($vars[0]);

这篇关于如何列出文件中的所有PHP变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆