Gav*_*vin 1 php preg-match-all
我使用以下代码来匹配以'$'开头的脚本中的所有变量,但是我希望结果不包含重复项,即不同/唯一:
preg_match_all('/\$[a-zA-Z0-9]+/', $code, $variables);
Run Code Online (Sandbox Code Playgroud)
有什么建议?
用于array_unique从输出数组中删除重复项:
preg_match_all('/\$[a-zA-Z0-9]+/', $code, $variables);
$variables = array_unique($variables[0]);
Run Code Online (Sandbox Code Playgroud)
但我希望你不要试图解析PHP.使用token_get_all来获取给定的PHP代码的令牌.