Page 1 of 1
string variable problem
Posted: Mon Dec 10, 2007 3:45 pm
by SirChick
I have this small script:
Code: Select all
<?php
$Multiply = 0.00;
$Input = 6;
settype($Multiply, "string");
settype($Input, "string");
Echo $Answer = $Multiply.$Input;
?>
But its not giving the correct result i want. I wanted it to show
0.006
How ever it is showing
06 instead.
Any one know where i went wrong ?
Posted: Mon Dec 10, 2007 3:51 pm
by s.dot
Just put the values in quotes to denote a string.
Code: Select all
C:\Users\scott>php -r "$multiply = '0.00'; $input = '6'; echo $multiply.$input;"
0.006
Posted: Mon Dec 10, 2007 4:39 pm
by SirChick
scottayy wrote:Just put the values in quotes to denote a string.
Code: Select all
C:\Users\scott>php -r "$multiply = '0.00'; $input = '6'; echo $multiply.$input;"
0.006
Ok that works which is what i got here:
Code: Select all
$multiply = '0.00';
$input = '6';
echo $multiply.$input;
How ever,
$input = '6';
Is coming from a $_POST['inputbox']
and is naturally going in as a number so how can i convert to string for it to use it cos when i did
settype($Input, "string");
to test it out it didnt work.
Posted: Mon Dec 10, 2007 5:10 pm
by s.dot
Coming from an input box, I imagine it will already be a string. However, you can just use type-casting.
Code: Select all
$input = (string) $_POST['input'];
Posted: Mon Dec 10, 2007 7:05 pm
by feyd
All elemental data coming from $_GET and $_POST is going to be a string already.