Overview
Installation
npm install php-parser --saveUsage
// initialize the php parser factory class
var fs = require('fs');
var path = require('path');
var engine = require('php-parser');
// initialize a new parser instance
var parser = new engine({
// some options :
parser: {
extractDoc: true,
php7: true
},
ast: {
withPositions: true
}
});
// Retrieve the AST from the specified source
var eval = parser.parseEval('echo "Hello World";');
// Retrieve an array of tokens (same as php function token_get_all)
var tokens = parser.tokenGetAll('<?php echo "Hello World";');
// Load a static file (Note: this file should exist on your computer)
var phpFile = fs.readFileSync( './example.php' );
// Log out results
console.log( 'Eval parse:', eval );
console.log( 'Tokens parse:', tokens );
console.log( 'File parse:', parser.parseCode(phpFile) );Sample AST output
API Overview
Documentation
Related projects
License
Last updated
Was this helpful?