Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
php-parser
Advanced tools
Readme
This JavaScript library parses PHP code and converts it to an AST.
This library is distributed with npm :
npm install php-parser --save
// initialize the php parser factory class
const fs = require("fs");
const path = require("path");
const engine = require("php-parser");
// initialize a new parser instance
const parser = new engine({
// some options :
parser: {
extractDoc: true,
php7: true,
},
ast: {
withPositions: true,
},
});
// Retrieve the AST from the specified source
const eval = parser.parseEval('echo "Hello World";');
// Retrieve an array of tokens (same as php function token_get_all)
const tokens = parser.tokenGetAll('<?php echo "Hello World";');
// Load a static file (Note: this file should exist on your computer)
const 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));
{
'kind': 'program',
'children': [
{
'kind': 'echo',
'arguments': [
{
'kind': 'string',
'isDoubleQuote': true,
'value': 'Hello World'
}
]
}
]
}
The main API exposes a class with the following methods :
You can also pass options that change the behavior of the parser/lexer.
You can add here your own project by opening an issue request.
This library is released under BSD-3 license clause.
FAQs
Parse PHP code from JS and returns its AST
The npm package php-parser receives a total of 108,075 weekly downloads. As such, php-parser popularity was classified as popular.
We found that php-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.