PHP code example of sabat24 / markdown-table

1. Go to this page and download the library: Download sabat24/markdown-table library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sabat24 / markdown-table example snippets


use sabat24\MarkdownTable\Table;

$table = new Table(['Branch', 'Commit']);
echo $table->getString([
    ['main', '0123456789abcdef'],
    ['staging', 'fedcba9876543210'],
]);

use sabat24\MarkdownTable\Table;

$table = new Table(['Beep', 'No.', 'Boop']);
$table->setAlignment(['l', 'c', 'r']);
echo $table->getString([
    ['beep', '1024', 'xyz'],
    ['boop', '3388450', 'tuv'],
    ['foo', '10106', 'qrstuv'],
    ['bar', '45', 'lmno'],
]);

use sabat24\MarkdownTable\Table;

$table = new Table(options: ['autoHeaders' => true]);
echo $table->getString([
    ['Col.A', 'Col.B', 'Col.C'],
    ['a', 'z', ''],
    ['b', '', ''],
    ['c', 'y', 'x'],
]);

use sabat24\MarkdownTable\Table;

// Using a custom function for handling special characters like emoji properly
function stringWidth($string): int
{
// This is a simplified example - in production, you might want
// a more sophisticated library that handles all Unicode properties
    $pattern = '/[\p{East_Asian_Width=F}\p{East_Asian_Width=W}]/u';
    $wide = preg_match_all($pattern, $string, $matches);

    return mb_strlen($string) + $wide;
}

$table = new Table(['Alpha', 'Bravo']);
$table->setStringLengthFunction('stringWidth');
echo $table->getString([
    ['中文', 'Charlie'],
    ['👩‍❤️‍👩', 'Delta'],
]);

use sabat24\MarkdownTable\Table;

$table = new Table(['Feature', 'Description']);
$table->setOptions(['allowedTags' => ['br', 'strong', 'em']]);
echo $table->getString([
    ['Line breaks', 'First line<br/>Second line'],
    ['Formatting', '<strong>Bold text</strong> and <em>italic text</em>'],
]);