3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $reg_exUrl = "/((http|https)\:\/\/|(www)\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; $text = 'some text http://mybreaktrip.cs.bsbm.eu/trip/view_bids/vienna-tripbsbm-ltd'; preg_match_all($reg_exUrl, $text, $matches); $usedPatterns = array(); foreach($matches[0] as $pattern){ if(!array_key_exists($pattern, $usedPatterns)) { $usedPatterns[$pattern] = true; if(!preg_match('%https://%',$pattern) && !preg_match('%http://%',$pattern)) { $start = "http://"; } if(strlen($pattern) > 18) { $parseurl = parse_url($pattern); $pattern_short = $host.substr($parseurl['path'], 0, 5).'(...)'.substr($parseurl['path'], -7); } $text = str_replace($pattern, "<a href='".(isset($start) ? $start : '')."{$pattern}' target='_blank'>".(isset($pattern_short) ? $pattern_short : $pattern)."</a> ", $text); } } echo $text;
Output for 5.0.4 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
Notice: Undefined variable: host in /in/iJSqk on line 17 some text <a href='http://mybreaktrip.cs.bsbm.eu/trip/view_bids/vienna-tripbsbm-ltd' target='_blank'>/trip(...)sbm-ltd</a>
Output for 4.3.0 - 5.0.3
Notice: Undefined variable: host in /in/iJSqk on line 17 some text <a href='http://mybreaktrip.cs.bsbm.eu/trip/view_bids/vienna-tripbsbm-ltd' target='_blank'>/trip(...)sbm-ltd</a>