sscanf_basic8.phpt 1.4 KB

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