{"id":13593214,"url":"https://github.com/vstelmakh/url-highlight","last_synced_at":"2026-04-03T19:02:10.322Z","repository":{"id":44531275,"uuid":"229620854","full_name":"vstelmakh/url-highlight","owner":"vstelmakh","description":"PHP library to parse URLs from string input","archived":false,"fork":false,"pushed_at":"2025-10-04T18:53:30.000Z","size":313,"stargazers_count":100,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-02-25T07:35:50.211Z","etag":null,"topics":["clickable","highlighter","html","linkify","parse-urls","parser","php","url","url-highlight"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vstelmakh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-12-22T19:41:57.000Z","updated_at":"2025-11-07T05:07:37.000Z","dependencies_parsed_at":"2023-02-09T23:00:54.831Z","dependency_job_id":"fe02b7bf-07e7-497f-b03c-fb9c9012fb81","html_url":"https://github.com/vstelmakh/url-highlight","commit_stats":{"total_commits":205,"total_committers":2,"mean_commits":102.5,"dds":"0.034146341463414664","last_synced_commit":"458f1af6acdf63d33e7fb43aeeecb4bfe64bda2b"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/vstelmakh/url-highlight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vstelmakh%2Furl-highlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vstelmakh%2Furl-highlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vstelmakh%2Furl-highlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vstelmakh%2Furl-highlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vstelmakh","download_url":"https://codeload.github.com/vstelmakh/url-highlight/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vstelmakh%2Furl-highlight/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31371647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clickable","highlighter","html","linkify","parse-urls","parser","php","url","url-highlight"],"created_at":"2024-08-01T16:01:17.795Z","updated_at":"2026-04-03T19:02:10.314Z","avatar_url":"https://github.com/vstelmakh.png","language":"PHP","funding_links":[],"categories":["PHP","Recently Updated","Table of Contents"],"sub_categories":["[Apr 12, 2025](/content/2025/04/12/README.md)","Globalization","Strings"],"readme":"\u003cimg src=\"./resources/url-highlight-logo.svg\" width=\"286\" height=\"93\" alt=\"Url highlight logo\"\u003e\n\n---\n\n[![Build status](https://github.com/vstelmakh/url-highlight/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/vstelmakh/url-highlight/actions/workflows/build.yml)\n[![Packagist version](https://img.shields.io/packagist/v/vstelmakh/url-highlight?color=orange)](https://packagist.org/packages/vstelmakh/url-highlight)\n[![PHP version](https://img.shields.io/packagist/php-v/vstelmakh/url-highlight)](https://www.php.net/)\n[![License](https://img.shields.io/github/license/vstelmakh/url-highlight?color=yellowgreen)](LICENSE)\n\n**Url highlight** - PHP library to parse URLs from string input. Works with complex URLs, edge cases and encoded input.  \n\nFeatures:\n- Replace URLs in string by HTML tags (make clickable)\n- Match URLs without scheme by top-level domain\n- Work with HTML entities encoded input\n- Extract URLs from string\n- Check if string is URL\n\n[🚀 **See examples** 👀](./docs/examples.md)\n\n## Installation\nInstall the latest version with [Composer](https://getcomposer.org/):  \n```bash\ncomposer require vstelmakh/url-highlight\n```\nAlso, there are\n [\u003cimg src=\"./resources/twig-logo.png\" width=\"8\" height=\"12\" alt=\"Twig logo\"\u003e Twig extension](https://github.com/vstelmakh/url-highlight-twig-extension)\n and [\u003cimg src=\"./resources/symfony-logo.png\" width=\"12\" height=\"12\" alt=\"Symfony logo\"\u003e Symfony bundle](https://github.com/vstelmakh/url-highlight-symfony-bundle) available.  \n\n## Quick start  \n```php\n\u003c?php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse VStelmakh\\UrlHighlight\\UrlHighlight;\n\n$urlHighlight = new UrlHighlight();\necho $urlHighlight-\u003ehighlightUrls('Hello, http://example.com.');\n\n// Output:\n// Hello, \u003ca href=\"http://example.com\"\u003ehttp://example.com\u003c/a\u003e.\n```\n\n\u003e 💡 **Tip**: For customizing highlight see [Highlighter](#highlighter).\n\u003e To properly handle HTML entity escaped string see [Encoder](#encoder).\n\n## Usage\n#### Check if string is URL\n```php\n\u003c?php\n$urlHighlight-\u003eisUrl('http://example.com'); // return: true\n$urlHighlight-\u003eisUrl('Other string'); // return: false\n```\n\n#### Parse URLs from string\n```php\n\u003c?php\n$urlHighlight-\u003egetUrls('Hello, http://example.com.');\n// return: ['http://example.com']\n```\n\n#### Replace URLs by HTML tags (make clickable)\n```php\n\u003c?php\n$urlHighlight-\u003ehighlightUrls('Hello, http://example.com.');\n// return: 'Hello, \u003ca href=\"http://example.com\"\u003ehttp://example.com\u003c/a\u003e.'\n```\n\n## Configuration\nThere are 3 parts which could be configured according to your needs:\n- [Validator](#validator) - define if match is valid and should be recognized as URL (e.g. allow/disallow specific schemes)\n- [Highlighter](#highlighter) - define the way how URL should be highlighted (e.g. replaced by html `\u003ca\u003e` tag)\n- [Encoder](#encoder) - define how to work with encoded input (e.g. html special chars)\n\nConfiguration provided via constructor implementing corresponding interface instance.\nUse `null` to keep default:  \n```php\n\u003c?php\nuse VStelmakh\\UrlHighlight\\Encoder\\HtmlSpecialcharsEncoder;\nuse VStelmakh\\UrlHighlight\\UrlHighlight;\nuse VStelmakh\\UrlHighlight\\Validator\\Validator;\n\n$validator = new Validator();\n$encoder = new HtmlSpecialcharsEncoder();\n$urlHighlight = new UrlHighlight($validator, null, $encoder);\n```\n\n### Validator\nThere is one validator bundled with the library. Which is used by default with settings listed in example below.  \n\n\u003cdetails\u003e\n    \u003csummary\u003e🛠️ Validator usage example\u003c/summary\u003e\n  \n```php\n\u003c?php\nuse VStelmakh\\UrlHighlight\\UrlHighlight;\nuse VStelmakh\\UrlHighlight\\Validator\\Validator;\n\n$validator = new Validator(\n    true, // bool - if should use top level domain to match urls without scheme\n    [],   // string[] - array of blacklisted schemes\n    [],   // string[] - array of whitelisted schemes\n    true  // bool - if should match emails (if match by TLD set to \"false\" - will match only \"mailto\" urls)\n);\n$urlHighlight = new UrlHighlight($validator);\n```\n\u003c/details\u003e\n\n\u003e 💡 **Tip**: If you need custom behavior - create and use your own validator implementing [ValidatorInterface](./src/Validator/ValidatorInterface.php).  \n\n### Highlighter\nThere are 2 highlighters bundled with the library:\n- [HtmlHighlighter](./src/Highlighter/HtmlHighlighter.php) - convert matches to html tags.  \n    Example: `http://example.com` \u0026rarr; `\u003ca href=\"http://example.com\"\u003ehttp://example.com\u003c/a\u003e`\n    \n- [MarkdownHighlighter](./src/Highlighter/MarkdownHighlighter.php) - convert matches to markdown format.  \n    Example: `http://example.com` \u0026rarr; `[http://example.com](http://example.com)`\n\nBy default, `HtmlHighlighter` is used, with settings listed in example below.  \n\n\u003cdetails\u003e\n    \u003csummary\u003e🛠️ Highlighter usage example\u003c/summary\u003e\n\n```php\n\u003c?php\nuse VStelmakh\\UrlHighlight\\Highlighter\\HtmlHighlighter;\nuse VStelmakh\\UrlHighlight\\UrlHighlight;\n\n$highlighter = new HtmlHighlighter(\n    'http', // string - scheme to use for urls matched by top level domain\n    [],     // string[] - key/value map of tag attributes, e.g. ['rel' =\u003e 'nofollow', 'class' =\u003e 'light']\n    '',     // string - content to add before highlight: {here}\u003ca...\n    ''      // string - content to add after highlight: ...\u003c/a\u003e{here}\n);\n$urlHighlight = new UrlHighlight(null, $highlighter);\n```\n\u003c/details\u003e\n\n\u003e 💡 **Tip**: If you need custom behavior - extend [HtmlHighlighter](./src/Highlighter/HtmlHighlighter.php) or implement [HighlighterInterface](./src/Highlighter/HighlighterInterface.php).  \n\u003e For more details and examples see [🖍️ Custom highlighter](./docs/highlighter-custom.md).  \n\n### Encoder\nEncoder should be used to handle encoded input properly. For example HTML escaped string could contain something\nlike: `http://example.com?a=1\u0026quot;` or `http://example.com?a=1\u0026amp;b=2` which will be wrongly matched as URL.\n\nBy default, there is no encoder used. There are 2 encoders bundled with library:\n- [HtmlEntitiesEncoder](./src/Encoder/HtmlEntitiesEncoder.php) - to work with HTML entities encoded string (any character expected to be HTML entity encoded)\n- [HtmlSpecialcharsEncoder](./src/Encoder/HtmlSpecialcharsEncoder.php) - to work with HTML escaped string (only `\u0026` `\"` `'` `\u003c` `\u003e` expected to be encoded)\n\n\u003cdetails\u003e\n    \u003csummary\u003e🛠️ Encoder usage example\u003c/summary\u003e\n\n```php\n\u003c?php\nuse VStelmakh\\UrlHighlight\\Encoder\\HtmlSpecialcharsEncoder;\nuse VStelmakh\\UrlHighlight\\UrlHighlight;\n\n$encoder = new HtmlSpecialcharsEncoder();\n$urlHighlight = new UrlHighlight(null, null, $encoder);\n\n$urlHighlight-\u003ehighlightUrls('\u0026lt;a href=\u0026quot;http://example.com\u0026quot;\u0026gt;Example\u0026lt;/a\u0026gt;');\n// return: '\u0026lt;a href=\u0026quot;\u003ca href=\"http://example.com\"\u003ehttp://example.com\u003c/a\u003e\u0026quot;\u0026gt;Example\u0026lt;/a\u0026gt;'\n```\n\u003c/details\u003e\n\n\u003e 💡 **Tip**: For custom behavior - create and use your own encoder implementing [EncoderInterface](./src/Encoder/EncoderInterface.php).  \n\u003e Keep in mind - using **encoder require more regex operations and could have performance impact**.\n\u003e Better to not use encoder if you don't expect encoded string.\n\n## Credits\n[Volodymyr Stelmakh](https://github.com/vstelmakh)  \nLicensed under the MIT License. See [LICENSE](LICENSE) for more information.  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvstelmakh%2Furl-highlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvstelmakh%2Furl-highlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvstelmakh%2Furl-highlight/lists"}