sscanf_basic5.phpt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. Test sscanf() function : basic functionality - exponential format
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] )
  6. * Description: Parses input from a string according to a format
  7. * Source code: ext/standard/string.c
  8. */
  9. echo "*** Testing sscanf() : basic functionality -using exponential format ***\n";
  10. $str = "10.12345 10.12345E3 10.12345e3 -10.12345e4" ;
  11. $format1 = "%e %e %e %e";
  12. $format2 = "%E %E %E %E";
  13. echo "\n-- Try sccanf() WITHOUT optional args --\n";
  14. // extract details using short format
  15. list($arg1, $arg2, $arg3, $arg4) = sscanf($str, $format1);
  16. var_dump($arg1, $arg2, $arg3, $arg4);
  17. list($arg1, $arg2, $arg3, $arg4) = sscanf($str, $format2);
  18. var_dump($arg1, $arg2, $arg3, $arg4);
  19. echo "\n-- Try sccanf() WITH optional args --\n";
  20. // extract details using long format
  21. $res = sscanf($str, $format1, $arg1, $arg2, $arg3, $arg4);
  22. var_dump($res, $arg1, $arg2, $arg3, $arg4);
  23. $res = sscanf($str, $format2,$arg1, $arg2, $arg3, $arg4);
  24. var_dump($res, $arg1, $arg2, $arg3, $arg4);
  25. ?>
  26. ===DONE===
  27. --EXPECT--
  28. *** Testing sscanf() : basic functionality -using exponential format ***
  29. -- Try sccanf() WITHOUT optional args --
  30. float(10.12345)
  31. float(10123.45)
  32. float(10123.45)
  33. float(-101234.5)
  34. float(10.12345)
  35. float(10123.45)
  36. float(10123.45)
  37. float(-101234.5)
  38. -- Try sccanf() WITH optional args --
  39. int(4)
  40. float(10.12345)
  41. float(10123.45)
  42. float(10123.45)
  43. float(-101234.5)
  44. int(4)
  45. float(10.12345)
  46. float(10123.45)
  47. float(10123.45)
  48. float(-101234.5)
  49. ===DONE===