3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function foo($str){ var_dump($str); var_dump( preg_match_all( '{^(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.3.0rc3
string(82) "http://www.answers.com/article/1194427/8-habits-of-extraordinarily-likeable-people" int(1) array(3) { [0]=> array(1) { [0]=> string(22) "http://www.answers.com" } [1]=> array(1) { [0]=> string(7) "http://" } [2]=> array(1) { [0]=> string(15) "www.answers.com" } } ---------------------------------------------string(21) "https://www.apple.com" int(1) array(3) { [0]=> array(1) { [0]=> string(21) "https://www.apple.com" } [1]=> array(1) { [0]=> string(8) "https://" } [2]=> array(1) { [0]=> string(13) "www.apple.com" } } ---------------------------------------------string(22) "https://www.apple .com" int(1) array(3) { [0]=> array(1) { [0]=> string(17) "https://www.apple" } [1]=> array(1) { [0]=> string(8) "https://" } [2]=> array(1) { [0]=> string(9) "www.apple" } } ---------------------------------------------string(17) "https://www.apple" int(1) array(3) { [0]=> array(1) { [0]=> string(17) "https://www.apple" } [1]=> array(1) { [0]=> string(8) "https://" } [2]=> array(1) { [0]=> string(9) "www.apple" } } ---------------------------------------------string(21) "http://www.cnn.com.au" int(1) array(3) { [0]=> array(1) { [0]=> string(21) "http://www.cnn.com.au" } [1]=> array(1) { [0]=> string(7) "http://" } [2]=> array(1) { [0]=> string(14) "www.cnn.com.au" } } ---------------------------------------------string(28) "http://downloads.news.com.au" int(1) array(3) { [0]=> array(1) { [0]=> string(28) "http://downloads.news.com.au" } [1]=> array(1) { [0]=> string(7) "http://" } [2]=> array(1) { [0]=> string(21) "downloads.news.com.au" } } ---------------------------------------------string(24) "http://ftp.android.co.nz" int(1) array(3) { [0]=> array(1) { [0]=> string(24) "http://ftp.android.co.nz" } [1]=> array(1) { [0]=> string(7) "http://" } [2]=> array(1) { [0]=> string(17) "ftp.android.co.nz" } } ---------------------------------------------string(21) "http://global.news.ca" int(1) array(3) { [0]=> array(1) { [0]=> string(21) "http://global.news.ca" } [1]=> array(1) { [0]=> string(7) "http://" } [2]=> array(1) { [0]=> string(14) "global.news.ca" } } ---------------------------------------------string(20) "http://www.apple.com" int(1) array(3) { [0]=> array(1) { [0]=> string(20) "http://www.apple.com" } [1]=> array(1) { [0]=> string(7) "http://" } [2]=> array(1) { [0]=> string(13) "www.apple.com" } } ---------------------------------------------string(9) "apple.com" int(1) array(3) { [0]=> array(1) { [0]=> string(9) "apple.com" } [1]=> array(1) { [0]=> string(0) "" } [2]=> array(1) { [0]=> string(9) "apple.com" } } ---------------------------------------------string(13) "www.apple.com" int(1) array(3) { [0]=> array(1) { [0]=> string(13) "www.apple.com" } [1]=> array(1) { [0]=> string(0) "" } [2]=> array(1) { [0]=> string(13) "www.apple.com" } } ---------------------------------------------