3v4l.org

run code in 500+ PHP versions simultaneously
<?php $str = " apply here https://ph.dbsd.com/job/dfvdfg/5444 and www.google.com also http://somesite.net "; $url_regex = "/\b((https?:\/\/?|www\.)[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/)))/"; preg_match_all($url_regex, $str, $matches); foreach($matches[0] as $match){ $anchor = "<a href='$match'>$match</a>"; $str = str_replace($match, $anchor, $str); } echo $str; var_dump($matches);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.6
apply here <a href='https://ph.dbsd.com/job/dfvdfg/5444'>https://ph.dbsd.com/job/dfvdfg/5444</a> and <a href='www.google.com'>www.google.com</a> also <a href='http://somesite.net'>http://somesite.net</a> array(4) { [0]=> array(3) { [0]=> string(35) "https://ph.dbsd.com/job/dfvdfg/5444" [1]=> string(14) "www.google.com" [2]=> string(19) "http://somesite.net" } [1]=> array(3) { [0]=> string(35) "https://ph.dbsd.com/job/dfvdfg/5444" [1]=> string(14) "www.google.com" [2]=> string(19) "http://somesite.net" } [2]=> array(3) { [0]=> string(8) "https://" [1]=> string(4) "www." [2]=> string(7) "http://" } [3]=> array(3) { [0]=> string(1) "4" [1]=> string(1) "m" [2]=> string(1) "t" } }

preferences:
92.1 ms | 1403 KiB | 4 Q