3v4l.org

run code in 300+ PHP versions simultaneously
<?php function autolink($str, $attributes=array()) { $attrs = ''; foreach ($attributes as $attribute => $value) { $attrs .= " {$attribute}=\"{$value}\""; } $str = ' ' . $str; $str = preg_replace( '`([^"=\'>])(((http|https|ftp)://|www.)[^\s<]+[^\s<\.)])`i', '$1<a href="$2"'.$attrs.'>$2</a>', $str ); $str = substr($str, 1); $str = preg_replace('`href=\"www`','href="http://www',$str); // fügt http:// hinzu, wenn nicht vorhanden return $str; } $text="PHP-Infos finden sich auf http://www.php.net und zu preg_replace()auf http://www.php.net/manual/de/function.preg-replace.php"; echo $text; echo "<br>"; echo autolink($text); ?>

preferences:
71.33 ms | 402 KiB | 5 Q