How to list all PHP variables in a file?

后端 未结 3 1561
不知归路
不知归路 2021-01-07 11:53

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

Hi ,
Can you please send me an email ?

I would like to

3条回答
  •  情深已故
    2021-01-07 12:41

    Depending on the expected accuracy a bit token_get_all() traversal will get you a list of variable basenames:

    print_r(
        array_filter(
            token_get_all($php_file_content),
            function($t) { return $t[0] == T_VARIABLE; }
        )
    );
    

    Just filter out [1] from that array structure.

    A bit less resilient, but sometimes still appropriate is a basic regex, which also allows to extract array variable or object syntax more easily.

提交回复
热议问题