Matching with character classes and anchors
<?php $thisFileContents = file_get_contents(__FILE__); $matchCount = preg_match_all('/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',$thisFileContents, $matches); print "Matches: $matchCount\n"; foreach ($matches[0] as $variableName) { print "$variableName\n"; } ?>