homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Convert String Expression to Value

 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.



 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;


 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.


 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 ::

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved