3v4l.org

run code in 300+ PHP versions simultaneously
<?php function txt2link($text){ // force http: on www. $text = preg_replace( "www\.", "http://www.", $text ); // eliminate duplicates after force $text = preg_replace( "http://http://www\.", "http://www.", $text ); $text = preg_replace( "https://http://www\.", "https://www.", $text ); // The Regular Expression filter $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; // Check if there is a url in the text if(preg_match($reg_exUrl, $text, $url)) { // make the urls hyper links $text = preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>', $text); } // if no urls in the text just return the text return ($text); } $str = 'Hi bro! Look at my new website: www.example.com. I leard to build websites from http://another.example.net and from example.net.'; $newStr = txt2link($str); echo $newStr;
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: preg_replace(): Delimiter must not be alphanumeric, backslash, or NUL in /in/57Wq8 on line 5 Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/57Wq8 on line 7 Warning: preg_replace(): Delimiter must not be alphanumeric, backslash, or NUL in /in/57Wq8 on line 7 Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/57Wq8 on line 8 Warning: preg_replace(): Delimiter must not be alphanumeric, backslash, or NUL in /in/57Wq8 on line 8 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /in/57Wq8 on line 13
Output for 8.1.0 - 8.1.28
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /in/57Wq8 on line 5 Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/57Wq8 on line 7 Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /in/57Wq8 on line 7 Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/57Wq8 on line 8 Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /in/57Wq8 on line 8 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /in/57Wq8 on line 13
Output for 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /in/57Wq8 on line 5 Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /in/57Wq8 on line 7 Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /in/57Wq8 on line 8
Output for 4.3.0 - 4.3.10
Warning: Delimiter must not be alphanumeric or backslash in /in/57Wq8 on line 5 Warning: Delimiter must not be alphanumeric or backslash in /in/57Wq8 on line 7 Warning: Delimiter must not be alphanumeric or backslash in /in/57Wq8 on line 8

preferences:
232.71 ms | 402 KiB | 314 Q