From 351fa2560f3c5b4b212b0c5c1819bbabca512146 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Wed, 21 Dec 2016 15:45:57 +0000 Subject: [PATCH] Add an option to only linkify URLs that start with a scheme Adding a `require_scheme` option allows a user to disable auto-linking of `www.example.com`, so that only full URLs (e.g. `https://www.example.com` are auto-linked. The scheme currently has to match `~^(ht|f)tps?://~`. Example usage: ```php $html = $linkify->processUrls($html, [ 'require_scheme' => true ]); ``` --- src/Misd/Linkify/Linkify.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Misd/Linkify/Linkify.php b/src/Misd/Linkify/Linkify.php index 0e3c9e6..9a574d2 100644 --- a/src/Misd/Linkify/Linkify.php +++ b/src/Misd/Linkify/Linkify.php @@ -164,7 +164,11 @@ protected function linkifyUrls($text, $options = array('attr' => '')) $pattern = "~^(ht|f)tps?://~"; if (0 === preg_match($pattern, $match[0])) { - $match[0] = 'http://' . $match[0]; + if (array_key_exists('require_scheme', $options) && $options['require_scheme']) { + return $caption; + } else { + $match[0] = 'http://' . $match[0]; + } } if (isset($options['callback'])) {