{"id":17263650,"url":"https://github.com/battye/php-array-parser","last_synced_at":"2025-04-14T07:53:00.489Z","repository":{"id":46045372,"uuid":"165661029","full_name":"battye/php-array-parser","owner":"battye","description":"Parse text representation of a PHP array into an actual PHP array.","archived":false,"fork":false,"pushed_at":"2021-11-18T04:36:58.000Z","size":46,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T21:38:54.037Z","etag":null,"topics":["array","parser","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/battye.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-14T12:51:56.000Z","updated_at":"2024-10-15T18:56:58.000Z","dependencies_parsed_at":"2022-09-09T02:50:24.013Z","dependency_job_id":null,"html_url":"https://github.com/battye/php-array-parser","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/battye%2Fphp-array-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/battye%2Fphp-array-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/battye%2Fphp-array-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/battye%2Fphp-array-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/battye","download_url":"https://codeload.github.com/battye/php-array-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248844082,"owners_count":21170486,"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":["array","parser","php"],"created_at":"2024-10-15T07:57:09.966Z","updated_at":"2025-04-14T07:53:00.461Z","avatar_url":"https://github.com/battye.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Array Parser\r\nA small library to parse text representations of a PHP array and return an actual PHP array.\r\n\r\n## Installation\r\n\r\nRun `composer install` to run this script (and tests) in a standalone way. Alternatively, this can be used as a dependency in another project by running `composer require battye/php-array-parser \"~1.0\"`.\r\n\r\nReference the namespace at the top of your PHP files to utilise the included classes:\r\n\r\n```php\r\nuse battye\\array_parser\\parser;\r\nuse battye\\array_parser\\tokens;\r\n```\r\n\r\nIf you notice any bugs, please raise an issue or pull request.\r\n\r\n## Example\r\n\r\nIn both of the following examples, `$result` would contain a PHP array containing the representation of the string or text file provided.\r\n\r\n### Raw String\r\n\r\nTo parse a simple array is very easy:\r\n\r\n```php\r\n$value = \"array(0 =\u003e array('one' =\u003e 1, 'two' =\u003e 'two'));\";\r\n$result = parser::parse_simple($value);\r\n```\r\n\r\nIn this case, `$result` would produce the following:\r\n\r\n    array(1) {\r\n      [0] =\u003e\r\n      array(2) {\r\n        'one' =\u003e\r\n        int(1)\r\n        'two' =\u003e\r\n        string(3) \"two\"\r\n      }\r\n    }\r\n\r\n### Regex\r\n\r\nRegular expressions can also be used to parse complex files and extract array values:\r\n\r\n```php\r\n$regex = '/\\$lang\\s+=\\s+array_merge\\(\\$lang, array\\((.*?)\\)\\);/s';\r\n$file = __DIR__ . '/files/test_lang.php';\r\n$result = parser::parse_regex($regex, $file);\r\n```\r\n\r\n## Tests\r\n\r\n[![Latest Stable Version](https://poser.pugx.org/battye/php-array-parser/v/stable)](https://packagist.org/packages/battye/php-array-parser) [![Total Downloads](https://poser.pugx.org/battye/php-array-parser/downloads)](https://packagist.org/packages/battye/php-array-parser) ![GitHub Actions CI](https://github.com/battye/php-array-parser/actions/workflows/phpunit.yaml/badge.svg?branch=master)\r\n\r\nThe unit tests provide good examples of how to utilise this library and can be found in the `tests/` directory. To execute the unit tests, run:\r\n\r\n    vendor/bin/simple-phpunit tests/\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbattye%2Fphp-array-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbattye%2Fphp-array-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbattye%2Fphp-array-parser/lists"}