{"id":24540657,"url":"https://github.com/mistralys/php-sprintf-parser","last_synced_at":"2025-08-11T02:10:15.718Z","repository":{"id":57017621,"uuid":"423111717","full_name":"Mistralys/php-sprintf-parser","owner":"Mistralys","description":"Parser to find all `sprintf` format placeholders in a string, and get information on them.","archived":false,"fork":false,"pushed_at":"2021-11-06T10:05:06.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-30T12:25:35.670Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mistralys.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-31T10:07:00.000Z","updated_at":"2021-11-01T16:11:56.000Z","dependencies_parsed_at":"2022-08-22T11:31:35.769Z","dependency_job_id":null,"html_url":"https://github.com/Mistralys/php-sprintf-parser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Mistralys/php-sprintf-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fphp-sprintf-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fphp-sprintf-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fphp-sprintf-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fphp-sprintf-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mistralys","download_url":"https://codeload.github.com/Mistralys/php-sprintf-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fphp-sprintf-parser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269819032,"owners_count":24480087,"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","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-01-22T18:14:34.196Z","updated_at":"2025-08-11T02:10:15.699Z","avatar_url":"https://github.com/Mistralys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sprintf format placeholders parser\n\nPHP-based parser class that can be used to find all format \nplaceholders of the [sprintf][] function in a string, and \nget information on them.\n\n\n\n## Requirements\n\n- PHP \u003e= 7.4\n\n## Installation\n\nSimply require the package via composer:\n\n```\ncomposer require php-sprintf-parser\n```\n\nOr add it to your `composer.json` manually:\n\n```json\n{\n  \"require\":{\n    \"mistralys/php-sprintf-parser\": \"^1.0\"\n  }\n}\n```\n\n## Usage\n\n### Parse texts with several placeholders\n\nFinding all formatting placeholders in a given string\ncan be done with the `parseString()` function.\n\n```php\nuse function Mistralys\\SprintfParser\\Functions\\parseString;\n\n$parser = parseString('The price of product %1$s has been set to %2$.2d EUR.');\n\n$placeholders = $parser-\u003egetPlaceholders();\n```\n\nEach placeholder instance can then be used to access\nall relevant information on the placeholder's configuration,\nlike its number (if any), precision, width, etc.\n\n### Parse individual formatting strings\n\nSingle placeholder format strings can also be parsed\nto retrieve information on the placeholder directly.\n\n```php\nuse function Mistralys\\SprintfParser\\Functions\\parseFormat;\n\n$placeholder = parseFormat('%1$.2d');\n```\n\n### Access placeholder information\n\nA placeholder gives access to all individual components of\na format string. As the official PHP documentation for [sprintf][]\nstates, the format prototype looks like this:\n\n```\n%[argnum$][flags][width][.precision]specifier\n```\n\nThe placeholder class allows easy access to each of these\ncomponents. The following is a valid format for example,\nwhich uses all possible options.\n\n```php\nuse function Mistralys\\SprintfParser\\Functions\\parseFormat;\n\n$placeholder = parseFormat(\"%1$+-0'*4.3d\");\n\n$placeholder-\u003egetSpecifier(); // s\n$placeholder-\u003egetNumber(); // 1\n$placeholder-\u003egetWidth(); // 4\n$placeholder-\u003egetPrecision(); // 3\n$placeholder-\u003egetPaddingChar(); // *\n$placeholder-\u003ehasPlusMinusPrefix(); // true\n$placeholder-\u003ehasLeftJustification(); // true\n$placeholder-\u003ehasOnlyZeroLeftPadding(); // true \n```\n\n\n[sprintf]:https://www.php.net/manual/en/function.sprintf.php\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fphp-sprintf-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmistralys%2Fphp-sprintf-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fphp-sprintf-parser/lists"}