{"id":27232871,"url":"https://github.com/sabat24/markdown-table","last_synced_at":"2026-02-16T11:34:00.274Z","repository":{"id":285100939,"uuid":"956990475","full_name":"sabat24/markdown-table","owner":"sabat24","description":"Generate GitHub Flavored Markdown tables in PHP from array.","archived":false,"fork":false,"pushed_at":"2025-04-06T08:26:43.000Z","size":33,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-27T16:29:49.271Z","etag":null,"topics":["gfm","markdown","markdown-table"],"latest_commit_sha":null,"homepage":"","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/sabat24.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-29T09:42:33.000Z","updated_at":"2025-11-25T02:08:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"6177512e-176c-4222-95f4-6c1d7a0a27e1","html_url":"https://github.com/sabat24/markdown-table","commit_stats":null,"previous_names":["sabat24/markdown-table"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/sabat24/markdown-table","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabat24%2Fmarkdown-table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabat24%2Fmarkdown-table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabat24%2Fmarkdown-table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabat24%2Fmarkdown-table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sabat24","download_url":"https://codeload.github.com/sabat24/markdown-table/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabat24%2Fmarkdown-table/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29506768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: 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":["gfm","markdown","markdown-table"],"created_at":"2025-04-10T14:10:16.959Z","updated_at":"2026-02-16T11:34:00.258Z","avatar_url":"https://github.com/sabat24.png","language":"PHP","readme":"# markdown-table\n\nGenerate a markdown (GFM) table in PHP.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n    * [Table Class](#table-class)\n    * [Column Class](#column-class)\n    * [Options](#options)\n* [Compatibility](#compatibility)\n\n## What is this?\n\nThis is a simple package that takes table data and generates a [GitHub flavored\nmarkdown (GFM)](https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/organizing-information-with-tables)\ntable in PHP.\n\n## When should I use this?\n\nYou can use this package when you want to generate the source code of a GFM\ntable from PHP data structures.\n\n## Inspiration\n\nThis is a PHP implementation inspired by the\nJavaScript [wooorm/markdown-table](https://github.com/wooorm/markdown-table)\npackage with similar API and functionality.\n\nI also made it compatible with [the-kbA-team/markdown-table](https://github.com/the-kbA-team/markdown-table) because I\nuse this package in some projects.\n\n## Install\n\nIn PHP projects, install with [Composer](https://getcomposer.org/):\n\n```sh\ncomposer require sabat24/markdown-table\n```\n\n## Use\n\nTypical usage (defaults to align left):\n\n```php\nuse sabat24\\MarkdownTable\\Table;\n\n$table = new Table(['Branch', 'Commit']);\necho $table-\u003egetString([\n    ['main', '0123456789abcdef'],\n    ['staging', 'fedcba9876543210'],\n]);\n```\n\nYields:\n\n```markdown\n| Branch  | Commit           |\n|---------|------------------|\n| main    | 0123456789abcdef |\n| staging | fedcba9876543210 |\n```\n\nWith align:\n\n```php\nuse sabat24\\MarkdownTable\\Table;\n\n$table = new Table(['Beep', 'No.', 'Boop']);\n$table-\u003esetAlignment(['l', 'c', 'r']);\necho $table-\u003egetString([\n    ['beep', '1024', 'xyz'],\n    ['boop', '3388450', 'tuv'],\n    ['foo', '10106', 'qrstuv'],\n    ['bar', '45', 'lmno'],\n]);\n```\n\nYields:\n\n```markdown\n| Beep |   No.   |   Boop |\n|:-----|:-------:|-------:|\n| beep |  1024   |    xyz |\n| boop | 3388450 |    tuv |\n| foo  |  10106  | qrstuv |\n| bar  |   45    |   lmno |\n```\n\nWith automatic headers:\n\n```php\nuse sabat24\\MarkdownTable\\Table;\n\n$table = new Table(options: ['autoHeaders' =\u003e true]);\necho $table-\u003egetString([\n    ['Col.A', 'Col.B', 'Col.C'],\n    ['a', 'z', ''],\n    ['b', '', ''],\n    ['c', 'y', 'x'],\n]);\n```\n\nYields:\n\n```markdown\n| Col.A | Col.B | Col.C |\n|-------|-------|-------|\n| a     | z     |       |\n| b     |       |       |\n| c     | y     | x     |\n```\n\nWith custom string length function:\n\n```php\nuse sabat24\\MarkdownTable\\Table;\n\n// Using a custom function for handling special characters like emoji properly\nfunction stringWidth($string): int\n{\n// This is a simplified example - in production, you might want\n// a more sophisticated library that handles all Unicode properties\n    $pattern = '/[\\p{East_Asian_Width=F}\\p{East_Asian_Width=W}]/u';\n    $wide = preg_match_all($pattern, $string, $matches);\n\n    return mb_strlen($string) + $wide;\n}\n\n$table = new Table(['Alpha', 'Bravo']);\n$table-\u003esetStringLengthFunction('stringWidth');\necho $table-\u003egetString([\n    ['中文', 'Charlie'],\n    ['👩‍❤️‍👩', 'Delta'],\n]);\n```\n\nWith allowed HTML tags:\n\n```php\nuse sabat24\\MarkdownTable\\Table;\n\n$table = new Table(['Feature', 'Description']);\n$table-\u003esetOptions(['allowedTags' =\u003e ['br', 'strong', 'em']]);\necho $table-\u003egetString([\n    ['Line breaks', 'First line\u003cbr/\u003eSecond line'],\n    ['Formatting', '\u003cstrong\u003eBold text\u003c/strong\u003e and \u003cem\u003eitalic text\u003c/em\u003e'],\n]);\n```\n\nYields:\n\n```markdown\n| Feature     | Description                                         |\n|-------------|-----------------------------------------------------|\n| Line breaks | First line\u003cbr/\u003eSecond line                          |\n| Formatting  | \u003cstrong\u003eBold text\u003c/strong\u003e and \u003cem\u003eitalic text\u003c/em\u003e |\n```\n\n# API\n\n### Table Class\n\n#### `__construct(array $columnNames = [], array $options = [], bool $useNamesAsPositions = false)`\n\nCreates a new table with:\n- `$columnNames`: Optional array of column names\n- `$options`: Optional configuration options\n- `$useNamesAsPositions`: When true, uses column names as position identifiers instead of array keys (default: false)\n\n#### `addColumn(int|string $pos, Column $column): Table`\n\nAdds a column to the table at the specified position.\n\n#### `getColumn(int|string $pos): Column`\n\nRetrieves a column at the specified position.\n\n#### `clearColumns(): Table`\n\nRemoves all columns from the table.\n\n#### `hasColumn(int|string $pos): bool`\n\nChecks if a column exists at the specified position.\n\n#### `hasColumns(): bool`\n\nChecks if the table has any columns defined.\n\n#### `dropColumn(int|string $pos): Table`\n\nRemoves a column at the specified position.\n\n#### `setStringLengthFunction(callable $callback): Table`\n\nSets a custom function to determine the visual length of strings, useful for handling CJK characters and emoji.\n\n#### `setAlignment(array|string $align): Table`\n\nSets alignment for columns. Accepts:\n- Single string for all columns: 'l'/'left', 'r'/'right', 'c'/'center'\n- Array of alignments for individual columns\n\n#### `setOptions(array $options): Table`\n\nSets configuration options for the table.\n\n#### `getOptions(): array`\n\nGets current configuration options.\n\n#### `getString(array $rows): string`\n\nGenerates a Markdown table string from the given rows.\n\n### Column Class\n\n#### `__construct(string $title, ?int $alignment = null)`\n\nCreates a new column with the specified title and optional alignment.\n\n#### `setAlignmentFromString(?string $alignment): Column`\n\nSets the column alignment using a string:\n- 'l' or 'left' for left alignment\n- 'r' or 'right' for right alignment\n- 'c' or 'center' for center alignment\n\n### Options\n\nThe following options can be passed to the `Table` constructor or `setOptions()` method:\n\n##### `alignDelimiters` (bool, default: `true`)\n\nWhether to align the delimiters. When `true`, they are aligned; when `false`, they are staggered.\n\n##### `padding` (bool, default: `true`)\n\nWhether to add a space of padding between delimiters and cells.\n\n##### `delimiterStart` (bool, default: `true`)\n\nWhether to begin each row with the delimiter.\n\n##### `delimiterEnd` (bool, default: `true`)\n\nWhether to end each row with the delimiter.\n\n##### `autoHeaders` (bool, default: `false`)\n\nWhether to use the first row of data as headers.\n\n##### `headerSeparatorPadding` (bool, default: `false`)\n\nWhether to add padding spaces in the header separator row.\n\n##### `allowedTags` (array, default: `[]`)\n\nAn array of HTML tags that should be preserved in the output. By default, all HTML is escaped, but you can specify tags like `['br', 'strong', 'em']` to allow these tags to remain unescaped in the generated table.\n\n## Compatibility\n\nThis package requires PHP 8.2 or higher.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsabat24%2Fmarkdown-table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsabat24%2Fmarkdown-table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsabat24%2Fmarkdown-table/lists"}