sscanf_basic2.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Test sscanf() function : basic functionality - integer 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. /*
  10. * Testing sscanf() : basic functionality
  11. */
  12. echo "*** Testing sscanf() : basic functionality - using integer format ***\n";
  13. $str = "Part: Widget Serial Number: 1234789 Stock: 25";
  14. $format = "Part: %s Serial Number: %d Stock: %d";
  15. echo "\n-- Try sccanf() WITHOUT optional args --\n";
  16. // extract details using short format
  17. list($part, $number, $stock) = sscanf($str, $format);
  18. var_dump($part, $number, $stock);
  19. echo "\n-- Try sccanf() WITH optional args --\n";
  20. // extract details using long format
  21. $res = sscanf($str, $format, $part, $number, $stock);
  22. var_dump($res, $part, $number, $stock);
  23. ?>
  24. ===DONE===
  25. --EXPECT--
  26. *** Testing sscanf() : basic functionality - using integer format ***
  27. -- Try sccanf() WITHOUT optional args --
  28. string(6) "Widget"
  29. int(1234789)
  30. int(25)
  31. -- Try sccanf() WITH optional args --
  32. int(3)
  33. string(6) "Widget"
  34. int(1234789)
  35. int(25)
  36. ===DONE===