0

I am trying to convert 08 and 09 to 8 and 9 respectively, but they are not getting converted.
I tried 08+0 , 09+0 but the result I obtained in both the cases is 0.
The above method is working for 01 to 07 and I am obtaining results as 1,2,...7, but not for 08 and 09. Please help me out.

Edited by daniel36

4
Contributors
6
Replies
29
Views
4 Years
Discussion Span
Last Post by masterjiraya
0

If you precede an integer with a zero, it is assumed to be in octal notation. If you need an integer outputted with a leading zero, use sprintf().

0

i also used (int)$var and number_format($var),sprintf but it still returning 0 for o8;

0

wait wait u said 08 not o8, its different. is it zero or leter O in front of the 8?

Edited by dorco

0

turn the string array by using explode function in this manner $var2array=explode("",$var); then use print_r($var2array)

it should have array with these value [0]=>'0', [1]=>'8' now to remove the 0 then you'll have to perform looping.

$var2array_2=array();
if($var2array[0]!=0){
echo $var=implode("",$var2array);
}//automatic ends if  block if first index is not 0
else{
for($i=0;$i<strlen($var);$i++)
if($var2array[0]==0){
$var2array[0]='';
}//very easy... because it just only first index to check
//what if there are more than 1 zero's
if($i>0)&&($var2array[$i-1]!=0){
array_push($var2array_2,$var2array[$i]);
}

}
echo implode("",$var2array_2);

in this code

if there is an input 0808 it shouldbe 808
if there's an input 008080 it shoulbe 8080

Edited by masterjiraya: relocating echo implode("",$var2array_2);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.