madlines/common-autolink
最新稳定版本:1.1
Composer 安装命令:
composer require madlines/common-autolink
包简介
Class that can convert urls into anchors
README 文档
README
It is a very simple lib that turns all urls in given input into anchors.
Installation
You can install it using composer:
composer require madlines/common-autolink
Usage
<?php use Madlines\Common\AutoLink\AutoLink; $input = 'My string containing some urls like www.example.com or smth more fancy like https://www.example.com:8803/foo/bar?lorem=ipsum#dolor/sit/amet'; $output = AutoLink::parse($input);
And it shall return the following string:
My string containing some urls like <a href="http://www.example.com" target="_blank">www.example.com</a> or smth more fancy like <a href="https://www.example.com:8803/foo/bar?lorem=ipsum#dolor/sit/amet" target="_blank">www.example.com:8803/foo/bar?lorem=ipsum#dolor/sit/amet</a>
For Symfony + Twig users
You can simply turn it into Twig extension if you'd like to:
<?php namespace MyApp\MyBundle\Twig; use Madlines\Common\AutoLink\AutoLink; class AutoLinkExtension extends \Twig_Extension { const NAME = 'auto_link_extension'; /** * @return array */ public function getFilters() { return [ new \Twig_SimpleFilter('auto_link', [$this, 'autoLink']), ]; } /** * @param string $text * @return string */ public function autoLink($text) { return AutoLink::parse($text) } /** * @return string */ public function getName() { return self::NAME; } }
service configuration in services.yml
my.twig_extension.auto_link: class: MyApp\MyBundle\Twig\AutoLinkExtension public: false tags: - { name: twig.extension }
统计信息
- 总下载量: 344
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-11