3v4l.org

run code in 300+ PHP versions simultaneously
<?php function foo($str){ var_dump($str); var_dump( preg_match( '{^(https?://)?([^/\n]+)}', $str, $matches ) ); var_dump($matches); } $strArray = [ 'http://www.answers.com/article/1194427/8-habits-of-extraordinarily-likeable-people', 'https://www.apple.com', 'https://www.apple .com', 'https://www.apple', 'http://www.cnn.com.au', 'http://downloads.news.com.au', 'http://ftp.android.co.nz', 'http://global.news.ca', 'http://www.apple.com', 'apple.com', 'www.apple.com', ]; foreach($strArray as $str){ foo($str); echo '---------------------------------------------'; }
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.4 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
string(82) "http://www.answers.com/article/1194427/8-habits-of-extraordinarily-likeable-people" int(1) array(3) { [0]=> string(22) "http://www.answers.com" [1]=> string(7) "http://" [2]=> string(15) "www.answers.com" } ---------------------------------------------string(21) "https://www.apple.com" int(1) array(3) { [0]=> string(21) "https://www.apple.com" [1]=> string(8) "https://" [2]=> string(13) "www.apple.com" } ---------------------------------------------string(22) "https://www.apple .com" int(1) array(3) { [0]=> string(17) "https://www.apple" [1]=> string(8) "https://" [2]=> string(9) "www.apple" } ---------------------------------------------string(17) "https://www.apple" int(1) array(3) { [0]=> string(17) "https://www.apple" [1]=> string(8) "https://" [2]=> string(9) "www.apple" } ---------------------------------------------string(21) "http://www.cnn.com.au" int(1) array(3) { [0]=> string(21) "http://www.cnn.com.au" [1]=> string(7) "http://" [2]=> string(14) "www.cnn.com.au" } ---------------------------------------------string(28) "http://downloads.news.com.au" int(1) array(3) { [0]=> string(28) "http://downloads.news.com.au" [1]=> string(7) "http://" [2]=> string(21) "downloads.news.com.au" } ---------------------------------------------string(24) "http://ftp.android.co.nz" int(1) array(3) { [0]=> string(24) "http://ftp.android.co.nz" [1]=> string(7) "http://" [2]=> string(17) "ftp.android.co.nz" } ---------------------------------------------string(21) "http://global.news.ca" int(1) array(3) { [0]=> string(21) "http://global.news.ca" [1]=> string(7) "http://" [2]=> string(14) "global.news.ca" } ---------------------------------------------string(20) "http://www.apple.com" int(1) array(3) { [0]=> string(20) "http://www.apple.com" [1]=> string(7) "http://" [2]=> string(13) "www.apple.com" } ---------------------------------------------string(9) "apple.com" int(1) array(3) { [0]=> string(9) "apple.com" [1]=> string(0) "" [2]=> string(9) "apple.com" } ---------------------------------------------string(13) "www.apple.com" int(1) array(3) { [0]=> string(13) "www.apple.com" [1]=> string(0) "" [2]=> string(13) "www.apple.com" } ---------------------------------------------
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 string(82) "http://www.answers.com/article/1194427/8-habits-of-extraordinarily-likeable-people" int(1) array(3) { [0]=> string(22) "http://www.answers.com" [1]=> string(7) "http://" [2]=> string(15) "www.answers.com" } ---------------------------------------------string(21) "https://www.apple.com" int(1) array(3) { [0]=> string(21) "https://www.apple.com" [1]=> string(8) "https://" [2]=> string(13) "www.apple.com" } ---------------------------------------------string(22) "https://www.apple .com" int(1) array(3) { [0]=> string(17) "https://www.apple" [1]=> string(8) "https://" [2]=> string(9) "www.apple" } ---------------------------------------------string(17) "https://www.apple" int(1) array(3) { [0]=> string(17) "https://www.apple" [1]=> string(8) "https://" [2]=> string(9) "www.apple" } ---------------------------------------------string(21) "http://www.cnn.com.au" int(1) array(3) { [0]=> string(21) "http://www.cnn.com.au" [1]=> string(7) "http://" [2]=> string(14) "www.cnn.com.au" } ---------------------------------------------string(28) "http://downloads.news.com.au" int(1) array(3) { [0]=> string(28) "http://downloads.news.com.au" [1]=> string(7) "http://" [2]=> string(21) "downloads.news.com.au" } ---------------------------------------------string(24) "http://ftp.android.co.nz" int(1) array(3) { [0]=> string(24) "http://ftp.android.co.nz" [1]=> string(7) "http://" [2]=> string(17) "ftp.android.co.nz" } ---------------------------------------------string(21) "http://global.news.ca" int(1) array(3) { [0]=> string(21) "http://global.news.ca" [1]=> string(7) "http://" [2]=> string(14) "global.news.ca" } ---------------------------------------------string(20) "http://www.apple.com" int(1) array(3) { [0]=> string(20) "http://www.apple.com" [1]=> string(7) "http://" [2]=> string(13) "www.apple.com" } ---------------------------------------------string(9) "apple.com" int(1) array(3) { [0]=> string(9) "apple.com" [1]=> string(0) "" [2]=> string(9) "apple.com" } ---------------------------------------------string(13) "www.apple.com" int(1) array(3) { [0]=> string(13) "www.apple.com" [1]=> string(0) "" [2]=> string(13) "www.apple.com" } ---------------------------------------------

preferences:
144.89 ms | 409 KiB | 135 Q