sscanf_basic8.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --TEST--
  2. Test sscanf() function : basic functionality - hexadecimal 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 hexadecimal format ***\n";
  10. $str = "129 12F 123B -123B 01ABC 1G";
  11. $format1 = "%x %x %x %x %x %x";
  12. $format2 = "%X %X %X %X %X %X";
  13. echo "\n-- Try sccanf() WITHOUT optional args --\n";
  14. // extract details using short format
  15. list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format1);
  16. var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
  17. list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format2);
  18. var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
  19. echo "\n-- Try sccanf() WITH optional args --\n";
  20. // extract details using long format
  21. $res = sscanf($str, $format1, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
  22. var_dump($res, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
  23. $res = sscanf($str, $format2, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
  24. var_dump($res, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
  25. ?>
  26. ===DONE===
  27. --EXPECT--
  28. *** Testing sscanf() : basic functionality - - using hexadecimal format ***
  29. -- Try sccanf() WITHOUT optional args --
  30. int(297)
  31. int(303)
  32. int(4667)
  33. int(-4667)
  34. int(6844)
  35. int(1)
  36. int(297)
  37. int(303)
  38. int(4667)
  39. int(-4667)
  40. int(6844)
  41. int(1)
  42. -- Try sccanf() WITH optional args --
  43. int(6)
  44. int(297)
  45. int(303)
  46. int(4667)
  47. int(-4667)
  48. int(6844)
  49. int(1)
  50. int(6)
  51. int(297)
  52. int(303)
  53. int(4667)
  54. int(-4667)
  55. int(6844)
  56. int(1)
  57. ===DONE===