Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Star width and precision in sprintf() --FILE-- <?php $f = 1.23456789012345678; ..

Decoded Output download

--TEST--
Star width and precision in sprintf()
--FILE--
<?php


$f = 1.23456789012345678;
$fx = 1.23456789012345678e100;
var_dump($f, $fx);

printf("%.*f
", 10, $f);
printf("%.*G
", 10, $f);
printf("%.*g
", -1, $fx);
printf("%.*G
", -1, $fx);
printf("%.*h
", -1, $fx);
printf("%.*H
", -1, $fx);
printf("%.*s
", 3, "foobar");
echo "
";

printf("%*f
", 10, $f);
printf("%*G
", 10, $f);
printf("%*s
", 10, "foobar");
echo "
";

printf("%*.*f
", 10, 3, $f);
printf("%*.*G
", 10, 3, $f);
printf("%*.*s
", 10, 3, "foobar");
echo "
";

printf("%1$.*2\$f
", $f, 10);
printf("%.*2\$f
", $f, 10);
printf("%2$.*f
", 10, $f);
printf("%1$*2\$f
", $f, 10);
printf("%*2\$f
", $f, 10);
printf("%2$*f
", 10, $f);
printf("%1$*2$.*3\$f
", $f, 10, 3);
printf("%*2$.*3\$f
", $f, 10, 3);
printf("%3$*.*f
", 10, 3, $f);
echo "
";

try {
    printf("%.*G
", "foo", 1.5);
} catch (ValueError $e) {
    echo $e->getMessage(), "
";
}

try {
    printf("%.*G
", -100, 1.5);
} catch (ValueError $e) {
    echo $e->getMessage(), "
";
}

try {
    printf("%.*s
", -1, "Foo");
} catch (ValueError $e) {
    echo $e->getMessage(), "
";
}

try {
    printf("%*G
", -1, $f);
} catch (ValueError $e) {
    echo $e->getMessage(), "
";
}

?>
--EXPECT--
float(1.2345678901234567)
float(1.2345678901234569E+100)
1.2345678901
1.23456789
1.2345678901234569e+100
1.2345678901234569E+100
1.2345678901234569e+100
1.2345678901234569E+100
foo

  1.234568
   1.23457
    foobar

     1.235
      1.23
       foo

1.2345678901
1.2345678901
1.2345678901
  1.234568
  1.234568
  1.234568
     1.235
     1.235
     1.235

Precision must be an integer
Precision must be between -1 and 2147483647
Precision -1 is only supported for %g, %G, %h and %H
Width must be greater than zero and less than 2147483647

Did this file decode correctly?

Original Code

--TEST--
Star width and precision in sprintf()
--FILE--
<?php


$f = 1.23456789012345678;
$fx = 1.23456789012345678e100;
var_dump($f, $fx);

printf("%.*f\n", 10, $f);
printf("%.*G\n", 10, $f);
printf("%.*g\n", -1, $fx);
printf("%.*G\n", -1, $fx);
printf("%.*h\n", -1, $fx);
printf("%.*H\n", -1, $fx);
printf("%.*s\n", 3, "foobar");
echo "\n";

printf("%*f\n", 10, $f);
printf("%*G\n", 10, $f);
printf("%*s\n", 10, "foobar");
echo "\n";

printf("%*.*f\n", 10, 3, $f);
printf("%*.*G\n", 10, 3, $f);
printf("%*.*s\n", 10, 3, "foobar");
echo "\n";

printf("%1$.*2\$f\n", $f, 10);
printf("%.*2\$f\n", $f, 10);
printf("%2$.*f\n", 10, $f);
printf("%1$*2\$f\n", $f, 10);
printf("%*2\$f\n", $f, 10);
printf("%2$*f\n", 10, $f);
printf("%1$*2$.*3\$f\n", $f, 10, 3);
printf("%*2$.*3\$f\n", $f, 10, 3);
printf("%3$*.*f\n", 10, 3, $f);
echo "\n";

try {
    printf("%.*G\n", "foo", 1.5);
} catch (ValueError $e) {
    echo $e->getMessage(), "\n";
}

try {
    printf("%.*G\n", -100, 1.5);
} catch (ValueError $e) {
    echo $e->getMessage(), "\n";
}

try {
    printf("%.*s\n", -1, "Foo");
} catch (ValueError $e) {
    echo $e->getMessage(), "\n";
}

try {
    printf("%*G\n", -1, $f);
} catch (ValueError $e) {
    echo $e->getMessage(), "\n";
}

?>
--EXPECT--
float(1.2345678901234567)
float(1.2345678901234569E+100)
1.2345678901
1.23456789
1.2345678901234569e+100
1.2345678901234569E+100
1.2345678901234569e+100
1.2345678901234569E+100
foo

  1.234568
   1.23457
    foobar

     1.235
      1.23
       foo

1.2345678901
1.2345678901
1.2345678901
  1.234568
  1.234568
  1.234568
     1.235
     1.235
     1.235

Precision must be an integer
Precision must be between -1 and 2147483647
Precision -1 is only supported for %g, %G, %h and %H
Width must be greater than zero and less than 2147483647

Function Calls

var_dump 1

Variables

$f 1.2345678901234567
$fx 12345678901234569000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Stats

MD5 51d1f941691968c83c3f715f07008767
Eval Count 0
Decode Time 86 ms