sscanf_basic3.phpt 967 B

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