Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Define $listify() $li helper function #51

Open
younishd opened this issue Jun 28, 2020 · 0 comments
Open

Define $listify() $li helper function #51

younishd opened this issue Jun 28, 2020 · 0 comments
Labels

Comments

@younishd
Copy link
Owner

younishd commented Jun 28, 2020

$listify = $li = function (
    array $items,
    string $item_format = '<li>%s</li>',
    string $list_format = '<ul>%s</ul>'
) {
    return \sprintf($list_format, \implode("\n", \array_map(function ($a) use ($item_format) {
        return \sprintf($item_format, \htmlspecialchars($a));
    }, $items)));
};
echo $li(["apple", "orange", "mango"]);
echo $listify(["apple", "orange", "mango"]);
echo $listify(["apple", "orange", "mango"], '<li class="fruit">%s<li>');
echo $listify(["apple", "orange", "mango"], '<li class="fruit">%s<li>', '<ol>%s</ol>');
<ul><li>apple</li>
<li>orange</li>
<li>mango</li></ul>

<ul><li>apple</li>
<li>orange</li>
<li>mango</li></ul>

<ul><li class="fruit">apple<li>
<li class="fruit">orange<li>
<li class="fruit">mango<li></ul>

<ol><li class="fruit">apple<li>
<li class="fruit">orange<li>
<li class="fruit">mango<li></ol>
@younishd younishd added this to the endobox 5 milestone Jun 29, 2020
@younishd younishd removed this from the endobox 5 milestone Jun 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant