An open API service indexing awesome lists of open source software.

https://github.com/smeghead/php-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.
https://github.com/smeghead/php-text-link-encoder

Last synced: 2 months ago
JSON representation

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.

Awesome Lists containing this project

README

        

# php-text-link-encoder

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](https://github.com/smeghead/php-text-link-encoder/actions/workflows/php.yml/badge.svg?event=push) [![Latest Stable Version](http://poser.pugx.org/smeghead/text-link-encoder/v)](https://packagist.org/packages/smeghead/text-link-encoder) [![Total Downloads](http://poser.pugx.org/smeghead/text-link-encoder/downloads)](https://packagist.org/packages/smeghead/text-link-encoder) [![Latest Unstable Version](http://poser.pugx.org/smeghead/text-link-encoder/v/unstable)](https://packagist.org/packages/smeghead/text-link-encoder) [![License](http://poser.pugx.org/smeghead/text-link-encoder/license)](https://packagist.org/packages/smeghead/text-link-encoder) [![PHP Version Require](http://poser.pugx.org/smeghead/text-link-encoder/require/php)](https://packagist.org/packages/smeghead/text-link-encoder)

## Features

* Converts urls and Emails in text to link tags.
* Other parts are properly encoded.

## Install

### From Composer

```bash
$ composer require smeghead/text-link-encoder
```

## Usage

```php
encode('Web Site: http://www.example.com/');
// -> Web Site: http://www.example.com/

echo $encoder->encode('Email: [email protected]');
// -> Email: [email protected]

echo $encoder->encode('alert(1); http://www.example.com/');
// -> <script>alert(1);</script> http://www.example.com/
```

Settings

```php
linkTarget('_self')
->convertNewLineToBrTag(false)
);
echo $encoder->encode("Web Site: http://www.example.com/\nDescription: ...");
// -> Web Site: http://www.example.com/
// Description: ...
```

## Development

### Open shell

```bash
docker compose build
docker compose run php_cli bash
```

### install dependencies

```bash
composer install
```

### execute tests

```bash
composer test
```

## Class Diagram

![Class Diagram](diagram.png)

## CONTRIBUTING

Both Issues and Pull Requests are welcome!