{"id":17124633,"url":"https://github.com/asika32764/php-autolink","last_synced_at":"2025-08-21T08:31:30.371Z","repository":{"id":33615955,"uuid":"37268183","full_name":"asika32764/php-autolink","owner":"asika32764","description":"A library to auto convert URL to link.","archived":false,"fork":false,"pushed_at":"2024-01-13T06:17:32.000Z","size":65,"stargazers_count":32,"open_issues_count":4,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-13T19:22:04.498Z","etag":null,"topics":["autolink","php-autolink","url-parser"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/asika/autolink","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/asika32764.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2015-06-11T15:05:12.000Z","updated_at":"2024-06-19T13:33:11.280Z","dependencies_parsed_at":"2024-01-13T09:46:25.816Z","dependency_job_id":null,"html_url":"https://github.com/asika32764/php-autolink","commit_stats":{"total_commits":36,"total_committers":3,"mean_commits":12.0,"dds":0.05555555555555558,"last_synced_commit":"7a166efd276454f1a3abff3749b9659ae86e96fb"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asika32764%2Fphp-autolink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asika32764%2Fphp-autolink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asika32764%2Fphp-autolink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asika32764%2Fphp-autolink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asika32764","download_url":"https://codeload.github.com/asika32764/php-autolink/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230236099,"owners_count":18194700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["autolink","php-autolink","url-parser"],"created_at":"2024-10-14T18:43:02.866Z","updated_at":"2025-08-21T08:31:30.364Z","avatar_url":"https://github.com/asika32764.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Autolink Library\n\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/asika32764/php-autolink/ci.yml?style=for-the-badge)\n[![Packagist Version](https://img.shields.io/packagist/v/asika/autolink?style=for-the-badge)\n](https://packagist.org/packages/asika/autolink)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/asika/autolink?style=for-the-badge)](https://packagist.org/packages/asika/autolink)\n\nA library to auto convert URLs to links.\n\n## Table of Content\n\n\u003c!-- TOC --\u003e\n* [PHP Autolink Library](#php-autolink-library)\n  * [Table of Content](#table-of-content)\n  * [Requirement](#requirement)\n  * [Installation via Composer](#installation-via-composer)\n  * [Getting Started](#getting-started)\n  * [Use Autolink Object](#use-autolink-object)\n  * [Convert Text](#convert-text)\n    * [Add Attributes](#add-attributes)\n  * [Convert Email](#convert-email)\n  * [Attributes Escaping](#attributes-escaping)\n  * [Options](#options)\n    * [`textLimit`](#textlimit)\n    * [`autoTitle`](#autotitle)\n    * [`stripScheme`](#stripscheme)\n    * [`escape`](#escape)\n    * [`linkNoScheme`](#linknoscheme)\n  * [Scheme](#scheme)\n  * [Link Builder](#link-builder)\n\u003c!-- TOC --\u003e\n\n## Requirement\n\n- Version 2.1.x require PHP 8.2 or higher.\n- Version 2.0.x require PHP 8.0 or higher.\n- Version 1.x supports PHP 5.3 to 7.4\n\n## Installation via Composer\n\nAdd this to composer.json require block.\n\n``` json\n{\n    \"require\": {\n        \"asika/autolink\": \"^2.0\"\n    }\n}\n```\n\n## Getting Started\n\nThis is a quick start to convert URL to link:\n\n```php\nuse Asika\\Autolink\\AutolinkStatic;\n\n$text = AutolinkStatic::convert($text);\n$text = AutolinkStatic::convertEmail($text);\n```\n\n## Use Autolink Object\n\nCreate the object:\n\n```php\nuse Asika\\Autolink\\Autolink;\n\n$autolink = new Autolink();\n```\n\nCreate with options.\n\n```php\nuse Asika\\Autolink\\AutolinkOptions;\n\n$options = new AutolinkOptions(\n    stripScheme: false,\n    textLimit: null,\n    autoTitle: false,\n    escape: true,\n    linkNoScheme: false\n);\n\n$schemes = ['http', 'https', 'skype', 'itunes'];\n\n$autolink = new Autolink($options, $schemes);\n```\n\n## Convert Text\n\nThis is an example text:\n\n``` html\nThis is Simple URL:\nhttp://www.google.com.tw\n\nThis is SSL URL:\nhttps://www.google.com.tw\n\nThis is URL with multi-level query:\nhttp://example.com/?foo[1]=a\u0026foo[2]=b\n```\n\nWe convert all URLs.\n\n```php\n$text = $autolink-\u003econvert($text);\n```\n\nOutput:\n\n``` html\nThis is Simple URL:\n\u003ca href=\"http://www.google.com.tw\"\u003ehttp://www.google.com.tw\u003c/a\u003e\n\nThis is SSL URL:\n\u003ca href=\"https://www.google.com.tw\"\u003ehttps://www.google.com.tw\u003c/a\u003e\n\nThis is URL with multi-level query:\n\u003ca href=\"http://example.com/?foo[1]=a\u0026amp;foo[2]=b\"\u003ehttp://example.com/?foo[1]=a\u0026amp;foo[2]=b\u003c/a\u003e\n```\n\n### Add Attributes\n\n```php\n$text = $autolink-\u003econvert($text, ['class' =\u003e 'center']);\n```\n\nAll link will add this attributes:\n\n```php\nThis is Simple URL:\n\u003ca href=\"http://www.google.com.tw\" class=\"center\"\u003ehttp://www.google.com.tw\u003c/a\u003e\n\nThis is SSL URL:\n\u003ca href=\"https://www.google.com.tw\" class=\"center\"\u003ehttps://www.google.com.tw\u003c/a\u003e\n```\n\n## Convert Email\n\nEmail url has no scheme, we use anoter method to convert them, and it will add `mailto:` at begin of `href`.\n\n```php\n$text = $autolink-\u003econvertEmail($text);\n```\n\nOutput\n\n``` html\n\u003ca href=\"mailto:foo@example.com\"\u003efoo@example.com\u003c/a\u003e\n\n```\n\n## Attributes Escaping\n\nAs `htmlspecialchars()` in PHP 8.1 or higher will escape single quote as default,\nAutolink will also escape single quote even in 8.0. Use this method to keep all escape\nbehavior same at any PHP versions:\n\n```php\n$autolink-\u003eescape('...');\n```\n\nIf you want to change the escape behavior, set your custom escape handler:\n\n```php\n$autolink-\u003esetEscapeHandler(fn =\u003e ...);\n```\n\n## Options\n\n### `textLimit`\n\nWe can set this option by constructor or setter:\n\n```php\n$autolink-\u003etextLimit(50);\n\n$text = $autolink-\u003econvert($text);\n```\n\nThe link text will be:\n\n```\nhttp://campus.asukademy.com/learning/job/84-fin...\n```\n\nUse Your own limit handler by set a callback:\n\n```php\n$autolink-\u003etextLimit(function($url) {\n    return substr($url, 0, 50) . '...';\n});\n```\n\nOr use `\\Asika\\Autolink\\LinkHelper::shorten()` Pretty handler:\n\n```php\n$autolink-\u003etextLimit(function($url) {\n    return \\Asika\\Autolink\\Autolink::shortenUrl($url, 15, 6);\n});\n```\n\nOutput:\n\n``` text\nhttp://campus.asukademy.com/....../84-find-interns......\n```\n\n### `autoTitle`\n\nUse AutoTitle to force add title on anchor element.\n\n```php\n$autolink-\u003eautoTitle(true);\n\n$text = $autolink-\u003econvert($text);\n```\n\nOutput:\n\n``` html\n\u003ca href=\"http://www.google.com.tw\" title=\"http://www.google.com.tw\"\u003ehttp://www.google.com.tw\u003c/a\u003e\n```\n\n### `stripScheme`\n\nStrip Scheme on link text:\n\n```php\n$autolink-\u003estripScheme(true);\n\n$text = $autolink-\u003econvert($text);\n```\n\nOutput\n\n``` html\n\u003ca href=\"http://www.google.com.tw\" \u003ewww.google.com.tw\u003c/a\u003e\n```\n\n### `escape`\n\nAuto escape URL, default is `true`:\n\n```php\n$autolink-\u003eautoEscape(false);\n\n$text = $autolink-\u003econvert($text);\n\n$autolink-\u003eautoEscape(true);\n\n$text = $autolink-\u003econvert($text);\n```\n\nOutput\n\n``` html\n\u003ca href=\"http://www.google.com.tw?foo=bar\u0026yoo=baz\" \u003ehttp://www.google.com.tw?foo=bar\u0026yoo=baz\u003c/a\u003e\n\u003ca href=\"http://www.google.com.tw?foo=bar\u0026amp;yoo=baz\" \u003ehttp://www.google.com.tw?foo=bar\u0026amp;yoo=baz\u003c/a\u003e\n```\n\n### `linkNoScheme`\n\nConvert URL which no scheme. If you pass `TRUE` to this option, Autolink will use\n`http` as default scheme, you can also provide your own default scheme.\n\n```php\n$autolink-\u003elinkNoScheme('https');\n\n$text = $autolink-\u003econvert('www.google.com.tw');\n```\n\nOutput\n\n``` html\n\u003ca href=\"https://www.google.com.tw\" \u003ewww.google.com.tw\u003c/a\u003e\n```\n\n## Scheme\n\nYou can add new scheme to convert URL begin with it, for example: `vnc://example.com`\n\n```php\n$autolink-\u003eaddScheme('skype', 'vnc');\n```\n\nDefault schemes is `http, https, ftp, ftps`.\n\n## Link Builder\n\nIf you don't want to use `\u003ca\u003e` element as your link, you can set a callback to build link HTML.\n\n```php\n$autolink-\u003esetLinkBuilder(function(string $url, array $attribs) {\n    $attribs['src'] = htmlspecialchars($url);\n\n    return \\Asika\\Autolink\\HtmlBuilder::create('img', $attribs, null);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasika32764%2Fphp-autolink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasika32764%2Fphp-autolink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasika32764%2Fphp-autolink/lists"}