Skip to content

Instantly share code, notes, and snippets.

@inlanger
Created June 2, 2013 15:43
Show Gist options
  • Save inlanger/5693890 to your computer and use it in GitHub Desktop.
Save inlanger/5693890 to your computer and use it in GitHub Desktop.
Parse PHP file for variables like $var = value;
def parse_php_variables(php):
'''
Parse PHP file for variables like $var = value;
'''
reg = r'\$([a-z]\w*)\s*=\s*\'(.*?)\';'
rg = re.compile(reg)
raw_variables = rg.findall(php)
variables = {}
for key, var in raw_variables:
variables[key] = var
return variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment