3v4l.org

run code in 300+ PHP versions simultaneously
<?php $url = "this is the link: https://stackoverflow.com/questions/ask"; $linktext = preg_replace_callback("/([\w]+\:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/", function ($m) { $url = $m[0]; $parts = parse_url($url); $parts["host"] = str_replace("www.", "", $parts["host"]); array_shift($parts); $shortURL = implode("", $parts); $shortenedURL = substr($shortURL, 0, 20); if (strlen($shortURL) > 20) $shortenedURL .= "..."; return "<a href=\"".$url."\">".$shortenedURL."</a>"; var_dump($parts); }, $url); echo $linktext;

preferences:
42.65 ms | 411 KiB | 5 Q