-
-
Save jasny/2000705 to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* Turn all URLs in clickable links. | |
* | |
* @param string $value | |
* @param array $protocols http/https, ftp, mail, twitter | |
* @param array $attributes | |
* @return string | |
*/ | |
public function linkify($value, $protocols = array('http', 'mail'), array $attributes = array()) | |
{ | |
// Link attributes | |
$attr = ''; | |
foreach ($attributes as $key => $val) { | |
$attr .= ' ' . $key . '="' . htmlentities($val) . '"'; | |
} | |
$links = array(); | |
// Extract existing links and tags | |
$value = preg_replace_callback('~(<a .*?>.*?</a>|<.*?>)~i', function ($match) use (&$links) { return '<' . array_push($links, $match[1]) . '>'; }, $value); | |
// Extract text links for each protocol | |
foreach ((array)$protocols as $protocol) { | |
switch ($protocol) { | |
case 'http': | |
case 'https': $value = preg_replace_callback('~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { if ($match[1]) $protocol = $match[1]; $link = $match[2] ?: $match[3]; return '<' . array_push($links, "<a $attr href=\"$protocol://$link\">$link</a>") . '>'; }, $value); break; | |
case 'mail': $value = preg_replace_callback('~([^\s<]+?@[^\s<]+?\.[^\s<]+)(?<![\.,:])~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"mailto:{$match[1]}\">{$match[1]}</a>") . '>'; }, $value); break; | |
case 'twitter': $value = preg_replace_callback('~(?<!\w)[@#](\w++)~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"https://twitter.com/" . ($match[0][0] == '@' ? '' : 'search/%23') . $match[1] . "\">{$match[0]}</a>") . '>'; }, $value); break; | |
default: $value = preg_replace_callback('~' . preg_quote($protocol, '~') . '://([^\s<]+?)(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { return '<' . array_push($links, "<a $attr href=\"$protocol://{$match[1]}\">{$match[1]}</a>") . '>'; }, $value); break; | |
} | |
} | |
// Insert all link | |
return preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) { return $links[$match[1] - 1]; }, $value); | |
} |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <http://unlicense.org/> |
You're wonderful!
Hey folks,
What is the input variable ?
How to place the output in anorther variable ?
You did it exactly what I need thank you so much.
have a blessing day
If the URL is in parentheses (www.example.com) this code will include the trailing parenthesis in the URL giving you this (www.example.com)
Thank you. It really works.
@jasny Will this detect (and skip) urls that are image sources? Example:
<img src="http://someurl.com">
Me too :)
Hello jasny,
This code is very helpful. Is it MIT licensed for open source use?
I am also curious about the licensing for this code.
Well, it`s a mind-boggling function and very useful. But I face issues here please anyone can suggest http://prntscr.com/nn9bv9.
In case: mailto I am getting any number along with URL like this <49>[email protected]. ScreenCast:- http://prntscr.com/nn9bv9
write like this:-
[email protected]
Do not prepend any text in mail. If do so it works fine. Well, I think it appends index number of an array
Allow display images and youtube video:
CSS class for links .htmllink and images .htmlimgpublic function linkify($showimg = 1, $value, $protocols = array('http', 'mail', 'https'), array $attributes = array('target' => '_blank')) { // Link attributes $attr = ''; foreach ($attributes as $key => $val) { $attr = ' ' . $key . '="' . htmlentities($val) . '"'; } $links = array(); // Extract existing links and tags $value = preg_replace_callback('~(<a .*?>.*?</a>|<.*?>)~i', function ($match) use (&$links) { return '<' . array_push($links, $match[1]) . '>'; }, $value); // Extract text links for each protocol foreach ((array)$protocols as $protocol) { switch ($protocol) { case 'http': case 'https': $value = preg_replace_callback('~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr, $showimg) { if ($match[1]){ $protocol = $match[1]; $link = $match[2] ?: $match[3]; // Youtube if($showimg == 1){ if(strpos($link, 'youtube.com')>=0 || strpos($link, 'youtu.be')>=0){ $link = '<iframe width="100%" height="315" src="https://www.youtube.com/embed/'.end(explode('=', $link)).'?rel=0&showinfo=0&color=orange&iv_load_policy=3" frameborder="0" allowfullscreen></iframe>'; return '<' . array_push($links, $link) . '></a>'; } if(strpos($link, '.png')>0 || strpos($link, '.jpg')>0 || strpos($link, '.jpeg')>0 || strpos($link, '.gif')>0 || strpos($link, '.bmp')>0){ return '<' . array_push($links, "<a $attr href=\"$protocol://$link\" class=\"htmllink\"><img src=\"$protocol://$link\" class=\"htmlimg\">") . '></a>'; } } return '<' . array_push($links, "<a $attr href=\"$protocol://$link\" class=\"htmllink\">$link</a>") . '>'; } }, $value); break; case 'mail': $value = preg_replace_callback('~([^\s<]+?@[^\s<]+?\.[^\s<]+)(?<![\.,:])~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"mailto:{$match[1]}\" class=\"htmllink\">{$match[1]}</a>") . '>'; }, $value); break; case 'twitter': $value = preg_replace_callback('~(?<!\w)[@#](\w++)~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"https://twitter.com/" . ($match[0][0] == '@' ? '' : 'search/%23') . $match[1] . "\" class=\"htmllink\">{$match[0]}</a>") . '>'; }, $value); break; default: $value = preg_replace_callback('~' . preg_quote($protocol, '~') . '://([^\s<]+?)(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { return '<' . array_push($links, "<a $attr href=\"$protocol://{$match[1]}\" class=\"htmllink\">{$match[1]}</a>") . '>'; }, $value); break; } } // Insert all link return preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) { return $links[$match[1] - 1]; }, $value); }
I have an error with this code ^^
Only variables should be passed by reference
On this line :
$link = '<iframe width="100%" height="315" src="https://www.youtube.com/embed/'.end(explode('=', $link)).'?rel=0&showinfo=0&color=orange&iv_load_policy=3" frameborder="0" allowfullscreen></iframe>';
My call :
echo TextHelper::linkify(1, 'un lien youtube : https://www.youtube.com/embed/sJeB24OLQis et un lien : https://www.brico.fr/');
Maybe is important, the function "linkify" is static.
public static function linkify($showimg = 1, $value, array $protocols = ['http', 'mail', 'https'], array $attributes = array('target' => '_blank'))
Thank you.
The function does not convert multiple types of links?
Example:
a youtube link: https://www.youtube.com/embed/sJeB24OLQis and a link: https://www.brico.fr/
It sends me 2 iframes Youtube which does not make sense to me.
I think I'm the only dummy guy here, I don't even know how to call the "linkify" method.. is it linkify($string) ? or what?
If the URL is in parentheses (www.example.com) this code will include the trailing parenthesis in the URL giving you this (www.example.com)
I have a similar problem. When an exclamation mark appears after the url, it ads the exclamation mark to the link.
have a similar problem. When an exclamation mark appears after the url, it ads the exclamation mark to the link.
@mhenke64 check out Url highlight library, it handles this and much more cases
Is it possible to have a variant whereby the www part of the URL is optional?
Solution from @MoovFun
Working sample:
<?php function Linkify(string $value, int $img = 1, int $video = 1, array $protocols = array('http', 'mail', 'twitter', 'https'), array $attributes = array('target' => '_blank'), $video_height = 400) { $attr = ""; foreach ($attributes as $key => $val) { $attr .= ' ' . $key . '="' . htmlentities($val) . '"'; } $links = array(); $value = preg_replace_callback('~(<a .*?>.*?</a>|<.*?>)~i', function ($match) use (&$links) { return '<' . array_push($links, $match[1]) . '>'; }, $value); foreach ((array)$protocols as $protocol) { switch ($protocol) { case 'http': case 'https': $value = preg_replace_callback('~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr, $img, $video, $video_height) { if ($match[1]){ $protocol = $match[1]; $link = $match[2] ?: $match[3]; if($video) { if(strpos($link, 'youtube.com') !== false || strpos($link, 'youtu.be') !== false){ $exp = explode('=', $link); $ht = '<iframe width="100%" height="'.$video_height.'" src="https://www.youtube.com/embed/'.end($exp).'?rel=0&showinfo=0&color=orange&iv_load_policy=3" frameborder="0" allowfullscreen></iframe>'; return '<' . array_push($links, $ht) . '></a>'; } if(strpos($link, 'vimeo.com') !== false){ $exp = explode('/', $link); $ht = '<iframe width="100%" height="'.$video_height.'" src="https://player.vimeo.com/video/'.end($exp).'" frameborder="0" allowfullscreen></iframe>'; return '<' . array_push($links, $ht) . '></a>'; } } if($img) { if(strpos($link, '.png') !== false || strpos($link, '.jpg') !== false || strpos($link, '.jpeg') !== false || strpos($link, '.gif') !== false || strpos($link, '.bmp') !== false || strpos($link, '.webp') !== false){ return '<' . array_push($links, "<a $attr href=\"$protocol://$link\" class=\"htmllink\"><img src=\"$protocol://$link\" class=\"htmlimg\">") . '></a>'; } } return '<' . array_push($links, "<a $attr href=\"$protocol://$link\" class=\"htmllink\">$link</a>") . '>'; } }, $value); break; case 'mail': $value = preg_replace_callback('~([^\s<]+?@[^\s<]+?\.[^\s<]+)(?<![\.,:])~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"mailto:{$match[1]}\" class=\"htmllink\">{$match[1]}</a>") . '>'; }, $value); break; case 'twitter': $value = preg_replace_callback('~(?<!\w)[@#]([\w\._]+)~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"https://twitter.com/" . ($match[0][0] == '@' ? '' : 'search/%23') . $match[1] . "\" class=\"htmllink\">{$match[0]}</a>") . '>'; }, $value); break; default: $value = preg_replace_callback('~' . preg_quote($protocol, '~') . '://([^\s<]+?)(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { return '<' . array_push($links, "<a $attr href=\"$protocol://{$match[1]}\" class=\"htmllink\">{$match[1]}</a>") . '>'; }, $value); break; } } return preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) { return $links[$match[1] - 1]; }, $value); }
use it
<?php echo Linkify('Twitter @twitter Email [email protected] Youtube https://www.youtube.com/watch?v=1BYrHIBs6ro Vimeo https://vimeo.com/282462734 Url http://google.com Image https://www.google.pl/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png Have a nice day hohoho!!!');
Be aware, this is not working properly with urls enclosed in brackets or quotes and punctuation.
Examples:
- Input: Brackets (http://example.com)
Output: Brackets (<a target="_blank" href="http://example.com)" class="htmllink">example.com)</a> - Input: Quotes "http://example.com"
Output: Quotes "<a target="_blank" href="http://example.com"" class="htmllink">example.com"</a> - Input: Exclamation mark http://example.com!
Output: Exclamation mark <a target="_blank" href="http://example.com!" class="htmllink">example.com!</a>
New solution from @MoovFun
Working sample:
function Linkify(string $value, int $img = 1, int $video = 1, array $protocols = array('http', 'mail', 'twitter', 'https'), array $attributes = array('target' => '_blank'), $video_height = 400) { $attr = ""; foreach ($attributes as $key => $val) { $attr .= ' ' . $key . '="' . htmlentities($val) . '"'; } $links = array(); $value = str_replace('(', '( ', $value); $value = str_replace(')', ' )', $value); $value = str_replace('"', '" ', $value); $value = str_replace('"', ' "', $value); $value = str_replace('!', ' !', $value); $value = preg_replace_callback('~(<a .*?>.*?</a>|<.*?>)~i', function ($match) use (&$links) { return '<' . array_push($links, $match[1]) . '>'; }, $value); foreach ((array)$protocols as $protocol) { switch ($protocol) { case 'http': case 'https': $value = preg_replace_callback('~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr, $img, $video, $video_height) { if ($match[1]){ $protocol = $match[1]; $link = $match[2] ?: $match[3]; $link = str_replace([')','!','"'],'',$link); if($video) { if(strpos($link, 'youtube.com') !== false || strpos($link, 'youtu.be') !== false){ $exp = explode('=', $link); $ht = '<iframe width="100%" height="'.$video_height.'" src="https://www.youtube.com/embed/'.end($exp).'?rel=0&showinfo=0&color=orange&iv_load_policy=3" frameborder="0" allowfullscreen></iframe>'; return '<' . array_push($links, $ht) . '></a>'; } if(strpos($link, 'vimeo.com') !== false){ $exp = explode('/', $link); $ht = '<iframe width="100%" height="'.$video_height.'" src="https://player.vimeo.com/video/'.end($exp).'" frameborder="0" allowfullscreen></iframe>'; return '<' . array_push($links, $ht) . '></a>'; } } if($img) { if(strpos($link, '.png') !== false || strpos($link, '.jpg') !== false || strpos($link, '.jpeg') !== false || strpos($link, '.gif') !== false || strpos($link, '.bmp') !== false || strpos($link, '.webp') !== false){ return '<' . array_push($links, "<a $attr href=\"$protocol://$link\" class=\"htmllink\"><img src=\"$protocol://$link\" class=\"htmlimg\">") . '></a>'; } } return '<' . array_push($links, "<a $attr href=\"$protocol://$link\" class=\"htmllink\">$link</a>") . '>'; } }, $value); break; case 'mail': $value = preg_replace_callback('~([^\s<]+?@[^\s<]+?\.[^\s<]+)(?<![\.,:])~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"mailto:{$match[1]}\" class=\"htmllink\">{$match[1]}</a>") . '>'; }, $value); break; case 'twitter': $value = preg_replace_callback('~(?<!\w)[@#]([\w\._]+)~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"https://twitter.com/" . ($match[0][0] == '@' ? '' : 'search/%23') . $match[1] . "\" class=\"htmllink\">{$match[0]}</a>") . '>'; }, $value); break; default: $value = preg_replace_callback('~' . preg_quote($protocol, '~') . '://([^\s<]+?)(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { return '<' . array_push($links, "<a $attr href=\"$protocol://{$match[1]}\" class=\"htmllink\">{$match[1]}</a>") . '>'; }, $value); break; } } $s = preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) { return $links[$match[1] - 1]; }, $value); $s = str_replace('( ', '(', $s); $s = str_replace(' )', ')', $s); $s = str_replace('" ', '"', $s); $s = str_replace(' "', '"', $s); return str_replace(' !', '!', $s); }
Use it
<?php $str = ' Brackets: (http://id.iot.com) Quotes: "http://id.iot.com" Exclamation: http://id.iot.com! Youtube https://www.youtube.com/watch?v=tpKCqp9CALQ Vimeo https://vimeo.com/331653781 Url http://google.com Image https://www.google.pl/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png Twitter @twitter Email [email protected]! <h2> Have a nice for all !!!</h2> '; echo Linkify($str);
Be aware, this is still not working properly with brackets, quotes and punctuation.
Examples:
- Input: Brackets https://en.wikipedia.org/wiki/Chaquicocha_(mountain)
Output: Brackets <a target="blank"href="https://en.wikipedia.org/wiki/Chaquicocha_("class="htmllink" >en.wikipedia.org/wiki/Chaquicocha( </a> mountain) - Input: Question mark http://example.com?
Output: <a target="_blank"href="http://example.com?"class="htmllink" >example.com? </a> - All the tag attributes glued together e.g.:
..._blank"href="http://example.com?"class...
Sample:
<?php
function Linkify(string $value, int $img = 1, int $video = 1, array $protocols = array('http', 'mail', 'twitter', 'https'), array $attributes = array('target' => '_blank'), $video_height = 400)
{
$links = array();
$value = preg_replace_callback('~(<a .*?>.*?</a>|<.*?>)~i', function ($match) use (&$links) { return '<' . array_push($links, $match[1]) . '>'; }, $value);
foreach ((array)$protocols as $protocol) {
switch ($protocol) {
case 'http':
case 'https':
$value = preg_replace_callback('~(?:\(?(https?)://([^\s\!]+)(?<![?,:.\"]))~i',
function ($match) use ($protocol, &$links, $attr, $img, $video, $video_height) {
if ($match[1]){
$protocol = $match[1];
$str = $match[0];
if($str[0] === '(') { $match[2] = substr($match[2],0,-1); }
$link = $match[2] ?: $match[3];
if($video) {
if(strpos($link, 'youtube.com') !== false || strpos($link, 'youtu.be') !== false){
$exp = explode('=', $link);
$ht = '<iframe width="100%" height="'.$video_height.'" src="https://www.youtube.com/embed/'.end($exp).'?rel=0&showinfo=0&color=orange&iv_load_policy=3" frameborder="0" allowfullscreen></iframe>';
return '<' . array_push($links, $ht) . '></a>';
}
if(strpos($link, 'vimeo.com') !== false){
$exp = explode('/', $link);
$ht = '<iframe width="100%" height="'.$video_height.'" src="https://player.vimeo.com/video/'.end($exp).'" frameborder="0" allowfullscreen></iframe>';
return '<' . array_push($links, $ht) . '></a>';
}
}
if($img) {
if(strpos($link, '.png') !== false || strpos($link, '.jpg') !== false || strpos($link, '.jpeg') !== false || strpos($link, '.gif') !== false || strpos($link, '.bmp') !== false || strpos($link, '.webp') !== false){
return '<' . array_push($links, "<a $attr href=\"$protocol://$link\" class=\"htmllink\"><img src=\"$protocol://$link\" class=\"htmlimg\">") . '></a>';
}
}
if($str[0] === '(') {
return '<' . array_push($links, "(<a $attr href=\"$protocol://$link\" class=\"htmllink\">$link</a>)") . '>';
} else {
return '<' . array_push($links, "<a $attr href=\"$protocol://$link\" class=\"htmllink\">$link</a>") . '>';
}
}
}, $value); break;
case 'mail': $value = preg_replace_callback('~([^\s<]+?@[^\s<]+?\.[^\s<]+)(?<![\.,:])~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"mailto:{$match[1]}\" class=\"htmllink\">{$match[1]}</a>") . '>'; }, $value); break;
case 'twitter': $value = preg_replace_callback('~(?<!\w)[@#]([\w\._]+)~', function ($match) use (&$links, $attr) { return '<' . array_push($links, "<a $attr href=\"https://twitter.com/" . ($match[0][0] == '@' ? '' : 'search/%23') . $match[1] . "\" class=\"htmllink\">{$match[0]}</a>") . '>'; }, $value); break;
default: $value = preg_replace_callback('~' . preg_quote($protocol, '~') . '://([^\s<]+?)(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { return '<' . array_push($links, "<a $attr href=\"$protocol://{$match[1]}\" class=\"htmllink\">{$match[1]}</a>") . '>'; }, $value); break;
}
}
return preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) { return $links[$match[1] - 1]; }, $value);
}
Use it:
<?php
$str = '
<a href="https://boom.doom"> Html LINK </a>
Youtube https://www.youtube.com/watch?v=tpKCqp9CALQ
Vimeo https://vimeo.com/331653781
Image https://www.google.pl/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png
Url http://google.com:
Input: Quotes "http://example.com"
Exlamation: http://example.com!
Exlamation: http://example.com?
Exlamation: http://example.com:
Exlamation: http://example.com.
Exlamation: http://example.com,
Brackets (http://example.com)
Brackets https://en.wikipedia.org/wiki/Chaquicocha_(mountain)
Twitter @twitter
Email [email protected]
<h2> html text </h2>
<style>.htmllink { font-weight: 900; color: #ff2255; padding: 10px; }</style>
';
echo Linkify((string) $str);
@MoovFun: Thanks so much for the code. It was really helpful for my project.
This is amazing. I've literally spent the last 30mins toying with preg_replace_callback
to try and do this myself, and through Googleing found that someone has already done it for me!
A hero!
Both solutions seem to cut off links when there are german umlauts present:
top: hashtag containing ä
bottom: hashtag partially detected as link, but only up to l
, then cut off
Unicode characters are not supported by the regex you are using for detecting hashtags .. I therefore propose to use another regex, like this: '/#([\p{Pc}\p{N}\p{L}\p{Mn}]+)/u'
(see here)
I wonder if anyone can update this to output the target destinations page title instead of outputting the links URL in the a element.
@userofit123 to accomplish that you'd have to query all the links and get the headers in return to change it to the desired output. If you have a lot of links the script will timeout or slow down the html output. Plus, you could be banned for sending too many server requests. So probably no one will try to add this.
@userofit123 to accomplish that you'd have to query all the links and get the headers in return to change it to the desired output. If you have a lot of links the script will timeout or slow down the html output. Plus, you could be banned for sending too many server requests. So probably no one will try to add this.
Yes makes sense!
How about changing the output URL to be just the target domain rather than the full URL?
So instead of it being:
<a href="https://github.com">https://github.com</a>
It would be:
<a href="https://github.com">github.com</a>
Or
<a href="https://github.com">github</a>
@userofit123 on line #27 you could try to change $link output:
<a $attr href=\"$protocol://$link\">$link</a>
<a $attr href=\"$protocol://$link\">'.str_replace("www.","",$link).'</a>
(untested, just the idea)
preg_replace('/^(www\.)?/i',"", parse_url($link, PHP_URL_HOST)))
That's what I ended up doing, similar to hat you suggested, thanks!
I also added the part to remove www so that it will be just the actual domain.
@caspChristian .. is that even a real-world use case? Why bother with invalid formats anyway?
I don't mean to be rude, on the contrary - I'm quite interested where you got this 🦊
@S1SYPHOS
In regards to: https://https://github.com
Would like to have only https://github.com since there is no port number after hostname.
Posting this as an interesting test case, of course depending on use case.
This is an example of user input, Or rather output from incorrect parsing of relative URL for redirect.
The data itself is from https://b800.org/3NynQ
@NiKiZe IMHO it's the developer's responsibility to prepare input before passing it to a function, simply replace https://https
with https://
yourself! The function itself should only work for 'valid' URIs .. jm2c
I have problem with accented characters on links. The output of the API is ok, but after linkify(), all my accented characters looks like �