{"id":13462231,"url":"https://github.com/glayzzle/php-parser","last_synced_at":"2025-05-14T03:10:32.466Z","repository":{"id":24271893,"uuid":"27666196","full_name":"glayzzle/php-parser","owner":"glayzzle","description":":herb: NodeJS PHP Parser - extract AST or tokens","archived":false,"fork":false,"pushed_at":"2024-12-31T07:30:28.000Z","size":30935,"stargazers_count":542,"open_issues_count":49,"forks_count":71,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-04-10T20:54:58.889Z","etag":null,"topics":["ast","development","javascript","lexer","parser","php","php-ast","php-parser","static-code-analysis","tokenizer"],"latest_commit_sha":null,"homepage":"https://php-parser.glayzzle.com/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glayzzle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":[],"patreon":"ichiriac","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2014-12-07T10:11:57.000Z","updated_at":"2025-03-05T10:49:17.000Z","dependencies_parsed_at":"2024-03-16T18:45:14.729Z","dependency_job_id":"f1fca76c-88e5-4464-9334-41e419f6eadf","html_url":"https://github.com/glayzzle/php-parser","commit_stats":{"total_commits":1466,"total_committers":41,"mean_commits":35.75609756097561,"dds":0.4113233287858117,"last_synced_commit":"b1168db8797dbda0ba890b660d0f74fdf5e88ae1"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glayzzle%2Fphp-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glayzzle%2Fphp-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glayzzle%2Fphp-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glayzzle%2Fphp-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glayzzle","download_url":"https://codeload.github.com/glayzzle/php-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254059512,"owners_count":22007769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","development","javascript","lexer","parser","php","php-ast","php-parser","static-code-analysis","tokenizer"],"created_at":"2024-07-31T12:00:42.747Z","updated_at":"2025-05-14T03:10:27.450Z","avatar_url":"https://github.com/glayzzle.png","language":"JavaScript","readme":"\u003ch1 align=\"center\"\u003ephp-parser\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n\u003ca title=\"npm version\" href=\"https://www.npmjs.com/package/php-parser\"\u003e\u003cimg src=\"https://badge.fury.io/js/php-parser.svg\"\u003e\u003c/a\u003e\n\u003ca title=\"npm downloads\" href=\"https://www.npmjs.com/package/php-parser\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/php-parser.svg?style=flat\"\u003e\u003c/a\u003e\n\u003ca title=\"Gitter\" href=\"https://gitter.im/glayzzle/Lobby\"\u003e\u003cimg src=\"https://img.shields.io/badge/GITTER-join%20chat-green.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003eThis JavaScript library parses PHP code and converts it to an AST.\u003c/p\u003e\n\n## Installation\n\nThis library is distributed with [npm](https://www.npmjs.com/package/php-parser) :\n\n```sh\nnpm install php-parser --save\n```\n\n## Usage\n\n```js\n// initialize the php parser factory class\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst engine = require(\"php-parser\");\n\n// initialize a new parser instance\nconst parser = new engine({\n  // some options :\n  parser: {\n    extractDoc: true,\n    php7: true,\n  },\n  ast: {\n    withPositions: true,\n  },\n});\n\n// Retrieve the AST from the specified source\nconst eval = parser.parseEval('echo \"Hello World\";');\n\n// Retrieve an array of tokens (same as php function token_get_all)\nconst tokens = parser.tokenGetAll('\u003c?php echo \"Hello World\";');\n\n// Load a static file (Note: this file should exist on your computer)\nconst phpFile = fs.readFileSync(\"./example.php\");\n\n// Log out results\nconsole.log(\"Eval parse:\", eval);\nconsole.log(\"Tokens parse:\", tokens);\nconsole.log(\"File parse:\", parser.parseCode(phpFile));\n```\n\n## Sample AST output\n\n```js\n{\n  'kind': 'program',\n  'children': [\n    {\n      'kind': 'echo',\n      'arguments': [\n        {\n          'kind': 'string',\n          'isDoubleQuote': true,\n          'value': 'Hello World'\n        }\n      ]\n    }\n  ]\n}\n```\n\n- Try it online (demo) : http://glayzzle.com/php-parser/\n- Or from AST Explorer : https://astexplorer.net/\n\n## API Overview\n\nThe main API exposes a class with the following methods :\n\n- **parseEval**(String|Buffer) : parse a PHP code in eval style mode (without php open tags)\n- **parseCode**(String|Buffer, String filename) : parse a PHP code by using php open tags.\n- **tokenGetAll**(String|Buffer) : retrieves a list of all tokens from the specified input.\n\nYou can also [pass options](https://github.com/glayzzle/php-parser/wiki/Options) that change the behavior of the parser/lexer.\n\n## Documentation\n\n- [AST nodes definition](https://php-parser.glayzzle.com/api/ast.js)\n- [Sandbox](https://php-parser.glayzzle.com/demo)\n- [List of options](https://php-parser.glayzzle.com/guides/options)\n\n## Related projects\n\n- [prettier/plugin-php](https://github.com/prettier/plugin-php) : Prettier PHP Plugin\n- [babel-preset-php](https://gitlab.com/kornelski/babel-preset-php) : Babel preset for converting PHP syntax to JavaScript. It can run subset of PHP in the browser or in Node.js\n- [wp-pot](https://github.com/rasmusbe/wp-pot) : Generate pot file for WordPress plugins and themes\n- [crane](https://github.com/HvyIndustries/crane) : PHP Intellisense/code-completion for VS Code\n- [php-unparser](https://github.com/chris-l/php-unparser) : Produce code that uses the style format recommended by PSR-1 and PSR-2.\n- [php-writer](https://github.com/glayzzle/php-writer) : Update PHP scripts from their AST\n- [ts-php-inspections](https://github.com/DaGhostman/ts-php-inspections) : Provide PHP code inspections written in typescript\n- [php-reflection](https://github.com/glayzzle/php-reflection) : Reflection API for PHP files\n- [vscode-phpunit](https://github.com/recca0120/vscode-phpunit) : vscode phpunit extension\n- [lua2php](https://www.npmjs.com/package/lua2php) : a Lua to PHP transpiler\n\n\u003e You can add here your own project by opening an issue request.\n\n## License\n\nThis library is released under BSD-3 license clause.\n","funding_links":["https://patreon.com/ichiriac"],"categories":["JavaScript","Uncategorized","PHP"],"sub_categories":["Uncategorized","JSX"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglayzzle%2Fphp-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglayzzle%2Fphp-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglayzzle%2Fphp-parser/lists"}