| Convert String Expression to Value
|
ocon

msg:4515686 | 12:26 am on Nov 5, 2012 (gmt 0) | I'm trying to read image exif data to determine its location. Unfortunately it appears it is stored in a convoluted manner. $exif = exif_read_data($file, 0, true); print_r($exif["GPS"]["GPSLatitude"]); // array("40/1","42/1","1224/25"); What I need to do is to resolve these fractions to get: 40, 42, 48.96 From that point I can take X+((Y+(Z/60))/60) = 40.7136 Unfortunately I cannot seem to resolve the fractions to even begin. echo $exif["GPS"]["GPSLatitude"][2]; // 1224/25 echo floatval($exif["GPS"]["GPSLatitude"][2]); // 1224 echo floatval($exif["GPS"]["GPSLatitude"][2]*1); // 1224 echo ($exif["GPS"]["GPSLatitude"][2]*1); // 1224 What I'm trying to do is convert a string like 1224/25 to the number 48.96.
|
lucy24

msg:4515697 | 1:19 am on Nov 5, 2012 (gmt 0) | Yes, it's dropping everything after the leading batch of numerics. If you need a placeholder function to let you carry on into the rest of the coding, you can do it by cheating: $bar = $exif["GPS"]["GPSLatitude"][2]; // $bar = "1224/25"; $place = strpos($bar,"/"); if ($place < strlen($bar)) { $first = substr($bar,0,$place); $second = substr($bar,$place+1); echo $first / $second; }
|
ocon

msg:4516070 | 10:18 pm on Nov 5, 2012 (gmt 0) | Thank you Lucy! I also found that I can explode on the slash. $seconds = explode("/", $exif["GPS"]["GPSLatitude"][2]); $seconds = $seconds[0]/$seconds[1]; It just seems strange, like there should be a simpler approach, but I guess not.
|
lucy24

msg:4516110 | 12:38 am on Nov 6, 2012 (gmt 0) | I could positively swear I found a command that interprets a string as a mathematical expression. But-- stop me if you've heard this one --when I went actively looking for it, it had vanished without a trace :( :: memo to self: remember the word "explode", which will save me time in own code ::
|
|
|