Jump to content

String to Value


Erazer

Recommended Posts

Hi
I'm using the EXIF functions to read camera setting of my photos. In some cases it returns the value as a string e.g 2.8 is returned as "28/10". Is there a function to convert the string into a numeric value?

sorry if this seems newbie question
thanks
Link to comment
Share on other sites

intval() will convert a variable to an integer, I think that's what you want.

$string = intval($string);

Edit: Also, floatval() will return a floating-point value.

[code=php:0]
$string = "45.9";
$int_string = intval($string);
$float_string = floatval($string);
echo ($int_string); // Will echo 45
echo ($float_string); // Will echo 45.9
[/code]
Link to comment
Share on other sites

Hi Jeremysr
thanks for the quick reply, I've tried the floatval() before but it doesnt seem to work if there is a operand in the string so

$string = "45.9";
$float_string = floatval($string);
echo ($float_string); // Will echo 45.9

but

$string = "45.9+10";
$float_string = floatval($string);
echo ($float_string); // Will also echo 45.9 and not 55.9

so i'm looking for something that will do the math in the string and out the result

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.