<?php
function sepNameDist($place){
$placeArr = explode("(",$place);
if(count($placeArr)>1){
$array['name'] = ucwords(trim($placeArr[0]));
$clean = strtolower(str_replace(" ","",trim(str_replace(")","",$placeArr[1]))));
$matches = (preg_split('#(?<=\d)(?=[a-z])#i', $clean));
$num = $matches[0];
$txt = $matches[1];
if($num < 1 and (trim(strtolower($txt)) == "km" or (trim(strtolower($txt)) == "kms"))){
$num = $num*1000;
$txt = "m";
$array['distance'] = $num." ".$txt;
}
else{
$array['distance'] = $num." ".$txt;
}
return $array;
}
else{
$placeArr = explode(" ",trim($place));
if(strtolower(trim($placeArr[count($placeArr)-1])) == "km" or strtolower(trim($placeArr[count($placeArr)-1])) == "kms"){
return strtolower(trim($placeArr[count($placeArr)-2]))." ".strtolower(trim($placeArr[count($placeArr)-1]))
}
}
}
print_r(sepNameDist("Birla Mandir 30 Km"));
- Output for 7.0.0 - 7.0.2
- Parse error: syntax error, unexpected '}', expecting ';' in /in/Q7MCK on line 27
Process exited with code 255. - Output for 5.5.24 - 5.5.31, 5.6.8 - 5.6.17
- Parse error: syntax error, unexpected '}' in /in/Q7MCK on line 27
Process exited with code 255.
preferences:
172.2 ms | 1395 KiB | 28 Q