Skip to content

Instantly share code, notes, and snippets.

@dcolish
Created August 8, 2010 17:57
Show Gist options
  • Save dcolish/514342 to your computer and use it in GitHub Desktop.
Save dcolish/514342 to your computer and use it in GitHub Desktop.
import ast
from phpparse import parser
input = '<?php echo "hello, world!"; ?>'
output = parser.parse(input)
map = {'Echo': ast.Print}
node_type, args = output[0].generic()
op = map[node_type](values=[ast.Str(args['nodes'].pop(), lineno=0,
col_offset=0)],
nl=True, lineno=0, col_offset=0)
body = [op]
expr = ast.Module(body)
eval(compile(ast.parse(expr), '<string>', mode='exec'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment