I am using the following code to match all variables in a script starting with ‘$’, however i would like the results to not contain duplicates, ie be distinct/unique:
preg_match_all('/\$[a-zA-Z0-9]+/', $code, $variables);
Any advice?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
array_uniqueto remove the duplicates from your output array:But I hope you’re not trying to parse PHP with that. Use
token_get_allto get the tokens of the given PHP code.