mrherman Posted September 9, 2011 Share Posted September 9, 2011 I have a long PHP script that I didn't write. I'd like to get a simple text list of all the unique variables from the script -- all variables within the script that begin with $, such as $_ADMIN $query $category $user $id $result, etc..... Any ideas how a PHP dabbler can go about this? I did a PHPFreaks search, but didn't find a thread on this. Thank you! Quote Link to comment Share on other sites More sharing options...
jcbones Posted September 9, 2011 Share Posted September 9, 2011 Get an editor that will do regular expression matching, and search for this: \$[^\s);]+ Quote Link to comment Share on other sites More sharing options...
WebStyles Posted September 9, 2011 Share Posted September 9, 2011 this will search and print out for any code starting with $ and ending with a space. it's not perfect though, cause if you have something like this $var="whatever"; there is no space after the variable. But it's a start. All your variables should show up on the list, except some will have other stuff after them. replace index.php for your file's name and place them in same directory. <?php $file = file_get_contents('index.php'); //echo $file; preg_match_all('/\$(.*?)\\s/is', $file, $matches); echo implode("<br>",$matches[0]); ?> Hope it helps EDIT: you can also apply array_unique to filter out duplicates. Quote Link to comment Share on other sites More sharing options...
mrherman Posted September 9, 2011 Author Share Posted September 9, 2011 Man, that was fast!! Thanks, fellas! Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 9, 2011 Share Posted September 9, 2011 Get an editor that will do regular expression matching, and search for this: Well, I would counter that a good editor will automatically display all the variables used in a script. Quote Link to comment Share on other sites More sharing options...
jcbones Posted September 9, 2011 Share Posted September 9, 2011 Get an editor that will do regular expression matching, and search for this: Well, I would counter that a good editor will automatically display all the variables used in a script. True, but I didn't say a good editor, I just said one that would support regular expressions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.