PHP Matching With Character Classes And Anchors – String Function

<?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";
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.