{"id":37002834,"url":"https://github.com/cego/php-fixed-length-file-parser","last_synced_at":"2026-01-14T00:30:42.595Z","repository":{"id":62500552,"uuid":"316324103","full_name":"cego/php-fixed-length-file-parser","owner":"cego","description":"A parser class for handling fixed length text files in PHP","archived":false,"fork":true,"pushed_at":"2021-03-30T05:04:10.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-22T02:22:27.266Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"fanatique/php-fixed-length-file-parser","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cego.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-11-26T19:49:22.000Z","updated_at":"2021-03-30T05:03:39.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/cego/php-fixed-length-file-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cego/php-fixed-length-file-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cego%2Fphp-fixed-length-file-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cego%2Fphp-fixed-length-file-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cego%2Fphp-fixed-length-file-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cego%2Fphp-fixed-length-file-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cego","download_url":"https://codeload.github.com/cego/php-fixed-length-file-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cego%2Fphp-fixed-length-file-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2026-01-14T00:30:41.888Z","updated_at":"2026-01-14T00:30:42.565Z","avatar_url":"https://github.com/cego.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"php-fixed-length-file-parser\n============================\n\nA parser class for handling fixed length text files in PHP.\n\nFixed Length Files (aka poor man's CSV) are plain text files with one data set per row\n_but without any delimiter_.\n\n    01Amy  BLUES\n    02Bob  REDS \n    ...\n\n## Features ##\n\nThis class provides a rather comfortable way to handle this type of file on PHP.\n\nYou can:\n\n- register a pre flight check to determine whether or not a row has to be parsed\n- register a callback to handle each line\n- register a chopping map which transforms each row into an assiciative array\n\n\n## Usage ##\n\nThe following example shows how to transform a fixed length file into an associative array.\nThe working example can be found in `example/parsing.php`.\n\n    $parser = new \\Fanatique\\Parser\\FixedLengthFileParser();\n\n    //Set the chopping map (aka where to extract the fields)\n    $parser-\u003esetChoppingMap(array(\n      array('field_name' =\u003e 'id', 'start' =\u003e 0, 'length' =\u003e 2),\n      array('field_name' =\u003e 'name', 'start' =\u003e 2, 'length' =\u003e 5),\n      array('field_name' =\u003e 'team', 'start' =\u003e 7, 'length' =\u003e 5),\n    ));\n\n``field_name`` and ``length`` are required and ``start`` is an optional parameter. If ``start`` is omitted, it will be set to the ``start`` plus ``length`` value of the previous map entry.\n\n    //Set the absolute path to the file\n    $parser-\u003esetFilePath(__DIR__ . '/example.dat');\n    \n    //Parse the file\n    try {\n      $parser-\u003eparse();\n    } catch (\\Fanatique\\Parser\\ParserException $e) {\n      echo 'ERROR - ' . $e-\u003egetMessage() . PHP_EOL;\n      exit(1);\n    }\n    \n    //Get the content\n    var_dump($parser-\u003egetContent());\n\n### Registering a pre flight check ###\n\nA pre flight check can be registered to be applied to each row *before* it is parsed.\nThe closure needs to return a boolean value with:\n\n- `false`: line needs not to be parsed\n- `true`: parse line \n\nThis example ignores any line which md5 sum is `f23f81318ef24f1ba4df4781d79b7849`:\n\n    $linesToIgnore = array('f23f81318ef24f1ba4df4781d79b7849');\n    $parser-\u003esetPreflightCheck(function($currentLineStr) use($linesToIgnore) {\n              if (in_array(md5($currentLineStr), $linesToIgnore)) {\n                  //Ignore line\n                  $ret = false;\n              } else {\n                  //Parse line\n                  $ret = true;\n              }\n              return $ret;\n          }\n    );\n\n### Registering a callback ###\n\nFinally you can register a callback which is applied to each parsed line and allows you to process it.\nThe closure gets the parsed line as an array and it is expected to return an array of the same format.\n\n    $parser-\u003esetCallback(function(array $currentLine) {\n                $currentLine['team'] = ucwords(strtolower($currentLine['team']));\n                return $currentLine;\n            }\n    );\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcego%2Fphp-fixed-length-file-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcego%2Fphp-fixed-length-file-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcego%2Fphp-fixed-length-file-parser/lists"}