chuoke/keyword-linkify

在文章中用链接替换关键词

1.0.1 2022-10-24 12:05 UTC

README

Latest Version on Packagist Tests Total Downloads

安装

您可以通过composer安装此包

composer require chuoke/keyword-linkify

用法

$text = '<img class="hero-logo" src="/images/logos/php-logo-white.svg" alt="php" width="240" height="120">
    <p class="hero-text">A <strong>popular general-purpose scripting language</strong> that is especially suited to web development.<br>Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.</p>';

$keywords = [
    [
        'keyword' => 'php',
        'url' => 'https://php.ac.cn/',
    ],
];

$keywordLinkify = new Chuoke\KeywordLinkify();
echo $keywordLinkify->replace($text, $keywords);

结果

<img class="hero-logo" src="/images/logos/php-logo-white.svg" alt="php" width="240" height="120"><p class="hero-text">A <strong>popular general-purpose scripting language</strong> that is especially suited to web development.<br>Fast, flexible and pragmatic, <a target="blank" href="https://php.ac.cn/" title="PHP">PHP</a> powers everything from your blog to the most popular websites in the world.</p>

如您所见,它不会替换属性文本。

更多示例请参阅测试。

测试

composer test

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

许可证

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