3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function get_last_dot_occurence ($url ) { $fullArray = explode('.', $url); $newArray = ""; switch (count($fullArray)) { case 1: $newArray = $url; break; case 2: $newArray = array("string1" => $fullArray[0], "string2" => $fullArray[1]); break; default: $string1 = ""; for ($i=0; $i < count($fullArray)-2; $i++) { $string1 .= $fullArray[$i]; if($i != count($fullArray)-3) $string1 .= '.'; } $string2 = $fullArray[count($fullArray)-2].'.'.$fullArray[count($fullArray)-1]; $newArray = array("string1" => $string1, "string2" => string2); break; } return $newArray; } print_r(get_last_dot_occurence("test.com")); print_r(get_last_dot_occurence("1.2.test.com"));
Output for 4.3.0 - 7.1.0
Array ( [string1] => test [string2] => com ) Notice: Use of undefined constant string2 - assumed 'string2' in /in/ZdTXJ on line 22 Array ( [string1] => 1.2 [string2] => string2 )