3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "<p>Some string www.test.com with urls http://test.com in it http://www.test.com.</p>"; if(preg_match_all("/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/",$text,$urls)){ foreach($urls[0]as $url ){ $text = str_replace($url,'<a href="'.$url.'">'.$url.'</a>',$text); } } echo $text;

preferences:
52.66 ms | 402 KiB | 5 Q