raryk/highlight

一个用于剪切链接和搜索的小型库

v1.0.0 2022-09-30 16:50 UTC

This package is auto-updated.

Last update: 2024-09-29 06:36:08 UTC


README

此库允许您突出显示文本和链接

安装

通过Composer

$ composer require raryk/highlight

用法

$highlight = new Highlight();

$highlight->setSearch('search text');
foreach($highlight->string('testing search text and link https://example.com') as $string) {
    if(isset($string['link'])) {
        echo '<a href="' . $string['link'] . '">';
        foreach($string['string'] as $string) {
            if($string['type'] == 'search') {
                echo '<span style="background:yellow;color:black">' . $string['text'] . '</span>';
            } else {
                echo '<span>' . $string['text'] . '</span>';
            }
        }
        echo '</a>';
    } else {
        if($string['type'] == 'search') {
            echo '<span style="background:yellow;color:black">' . $string['text'] . '</span>';
        } else {
            echo '<span>' . $string['text'] . '</span>';
        }
    }
}

echo '<br><br>';

$highlight->setSearch('and link https://');
foreach($highlight->string('testing search text and link https://example.com') as $string) {
    if(isset($string['link'])) {
        echo '<a href="' . $string['link'] . '">';
        foreach($string['string'] as $string) {
            if($string['type'] == 'search') {
                echo '<span style="background:yellow;color:black">' . $string['text'] . '</span>';
            } else {
                echo '<span>' . $string['text'] . '</span>';
            }
        }
        echo '</a>';
    } else {
        if($string['type'] == 'search') {
            echo '<span style="background:yellow;color:black">' . $string['text'] . '</span>';
        } else {
            echo '<span>' . $string['text'] . '</span>';
        }
    }
}

贡献

请参阅CONTRIBUTING以获取详细信息。

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。