outofboxlab/linkify-bundle

将文本中的URL和电子邮件地址转换为HTML链接

安装: 86

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 7

开放问题: 0

类型:symfony-bundle

dev-master / 1.0.2.x-dev 2023-12-07 18:01 UTC

This package is auto-updated.

Last update: 2024-09-07 19:37:04 UTC


README

Build Status

Linkify添加到您的Symfony应用程序中,它可以将HTML(或纯文本)中的URL和电子邮件地址转换为HTML链接。

安装

  1. 将LinkifyBundle添加到您的依赖项中

    $ composer require misd/linkify-bundle
    
  2. 在您的应用程序中注册该包

    // app/AppKernel.php
    
    class AppKernel extends Kernel
    {
        // ...
        public function registerBundles()
        {
            $bundles = array(
                // ...
                new Misd\LinkifyBundle\MisdLinkifyBundle(),
                // ...
            );
        }
        // ...
    }
    

使用方法

使用服务

$text = $this->container->get('misd.linkify')->process('This is my text containing a link to www.example.com.');

在Twig模板中

{{ "This is my text containing a link to www.example.com."|linkify }}

在PHP模板中

<?php echo $view['linkify']->process('This is my text containing a link to www.example.com.') ?>

选项

需要Linkify v1.1.1或更高版本。

可以传递一个选项数组(有关更多信息,请参阅Linkify文档)。例如,要为创建的链接添加link

使用服务

$text = $this->container->get('misd.linkify')->process('This is my text containing a link to www.example.com.', array('attr' => array('class' => 'link')));

在Twig模板中

{{ "This is my text containing a link to www.example.com."|linkify({'attr': {'class': 'link'}}) }}

在PHP模板中

<?php echo $view['linkify']->process('This is my text containing a link to www.example.com.', array('attr' => array('class' => 'link'))) ?>