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.
- Host: GitHub
- URL: https://github.com/smeghead/php-text-link-encoder
- Owner: smeghead
- License: apache-2.0
- Created: 2023-08-22T12:35:46.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-06T13:43:55.000Z (over 1 year ago)
- Last Synced: 2025-02-07T22:53:43.781Z (4 months ago)
- Language: PHP
- Homepage:
- Size: 230 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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.
 [](https://packagist.org/packages/smeghead/text-link-encoder) [](https://packagist.org/packages/smeghead/text-link-encoder) [](https://packagist.org/packages/smeghead/text-link-encoder) [](https://packagist.org/packages/smeghead/text-link-encoder) [](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

## CONTRIBUTING
Both Issues and Pull Requests are welcome!