smeghead/text-link-encoder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

Testing Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

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/');
// -> &lt;script&gt;alert(1);&lt;/script&gt; <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

Class Diagram

CONTRIBUTING

Both Issues and Pull Requests are welcome!

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2023-08-24