0

I was able to use these Stack questions to implement file_get_contents and is_numeric to have the following code successfully provide me a distance in a numerical value between two lat/long points. If the system I'm sending the values to cannot provide a time it outputs a [FAILED] and then I display the text "Unroutable".

This is my working code:

  $distance = file_get_contents("http://myserver.com/geo/traveltimes.php?start=".$row["Lat"].",".$row["Lon"]."&dest=".$user["Latitude"].",".$user["Longitude"]."");     

  $row["Distance"] = is_numeric($distance) ? $distance : "Unroutable";

I'd like as a last ditch effort to reverse the 'start' & 'dest' values to try to see if I can return some numerical results that way.

What is the best way to "trap" a non-numerical value like the [FAILED] and reverse these and THEN display Unroutable if no numerical value is displayed?

Community
  • 1
  • 1
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79

1 Answers1

0

Are you just looking for an if statement?:

$distance = file_get_contents("http://myserver.com/geo/traveltimes.php?start=".$row["Lat"].",".$row["Lon"]."&dest=".$user["Latitude"].",".$user["Longitude"]."");     

if (!is_numeric($distance)) {
    $distance = file_get_contents("http://myserver.com/geo/traveltimes.php?start=".$user["Latitude"].",".$user["Longitude"]."&dest=".$row["Lat"].",".$row["Lon"].""); 
}

$row["Distance"] = is_numeric($distance) ? $distance : "Unroutable";
David
  • 208,112
  • 36
  • 198
  • 279