smeghead/text-link-encoder
最新稳定版本:v0.2.1
Composer 安装命令:
composer require smeghead/text-link-encoder
包简介
A library that converts any string containing a URL (such as a user-entered string) into a html string containing url link. Non-URL parts are html-encoded.
README 文档
README
A library that converts any string containing URLs and Emails (such as a user-entered string) into a html string containing url link. Non-URL parts are html-encoded.
Features
- Converts urls and Emails in text to link tags.
- Other parts are properly encoded.
Install
From Composer
$ composer require smeghead/text-link-encoder
Usage
<?php require_once(__DIR__ . '/../vendor/autoload.php'); use Smeghead\TextLinkEncoder\TextLinkEncoder; use Smeghead\TextLinkEncoder\Config\TextLinkEncoderSettings; $encoder = new TextLinkEncoder(new TextLinkEncoderSettings()); echo $encoder->encode('Web Site: http://www.example.com/'); // -> Web Site: <a href="http://www.example.com/" target="_blank" rel="noreferrer noopener">http://www.example.com/</a> echo $encoder->encode('Email: info@example.com'); // -> Email: <a href="mailto:info@example.com" target="_blank" rel="noreferrer noopener">info@example.com</a> echo $encoder->encode('<script>alert(1);</script> http://www.example.com/'); // -> <script>alert(1);</script> <a href="http://www.example.com/" target="_blank" rel="noreferrer noopener">http://www.example.com/</a>
Settings
<?php require_once(__DIR__ . '/../vendor/autoload.php'); use Smeghead\TextLinkEncoder\TextLinkEncoder; use Smeghead\TextLinkEncoder\Config\TextLinkEncoderSettings; $encoder = new TextLinkEncoder( (new TextLinkEncoderSettings()) ->linkTarget('_self') ->convertNewLineToBrTag(false) ); echo $encoder->encode("Web Site: http://www.example.com/\nDescription: ..."); // -> Web Site: <a href="http://www.example.com/" target="_self" rel="noreferrer noopener">http://www.example.com/</a> // Description: ...
Development
Open shell
docker compose build docker compose run php_cli bash
install dependencies
composer install
execute tests
composer test
Class Diagram
CONTRIBUTING
Both Issues and Pull Requests are welcome!
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2023-08-24
