sscanf_basic3.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Test sscanf() function : basic functionality - float 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 float format ***\n";
  10. $str = "Part: Widget Length: 111.53 Width: 22.345 Depth: 12.4";
  11. $format = "Part: %s Length: %f Width: %f Depth: %f";
  12. echo "\n-- Try sccanf() WITHOUT optional args --\n";
  13. // extract details using short format
  14. list($part, $length, $width, $depth) = sscanf($str, $format);
  15. var_dump($part, $length, $width, $depth);
  16. echo "\n-- Try sccanf() WITH optional args --\n";
  17. // extract details using long format
  18. $res = sscanf($str, $format, $part, $length, $width, $depth);
  19. var_dump($res, $part, $length, $width, $depth);
  20. ?>
  21. ===DONE===
  22. --EXPECT--
  23. *** Testing sscanf() : basic functionality -- using float format ***
  24. -- Try sccanf() WITHOUT optional args --
  25. string(6) "Widget"
  26. float(111.53)
  27. float(22.345)
  28. float(12.4)
  29. -- Try sccanf() WITH optional args --
  30. int(4)
  31. string(6) "Widget"
  32. float(111.53)
  33. float(22.345)
  34. float(12.4)
  35. ===DONE===