1--TEST-- 2Test sscanf() function : basic functionality - hexadecimal format 3--FILE-- 4<?php 5 6/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) 7 * Description: Parses input from a string according to a format 8 * Source code: ext/standard/string.c 9*/ 10 11echo "*** Testing sscanf() : basic functionality - - using hexadecimal format ***\n"; 12 13$str = "129 12F 123B -123B 01ABC 1G"; 14$format1 = "%x %x %x %x %x %x"; 15$format2 = "%X %X %X %X %X %X"; 16 17echo "\n-- Try sccanf() WITHOUT optional args --\n"; 18// extract details using short format 19list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format1); 20var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 21list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format2); 22var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 23 24echo "\n-- Try sccanf() WITH optional args --\n"; 25// extract details using long format 26$res = sscanf($str, $format1, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 27var_dump($res, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 28$res = sscanf($str, $format2, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 29var_dump($res, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 30 31?> 32===DONE=== 33--EXPECT-- 34*** Testing sscanf() : basic functionality - - using hexadecimal format *** 35 36-- Try sccanf() WITHOUT optional args -- 37int(297) 38int(303) 39int(4667) 40int(-4667) 41int(6844) 42int(1) 43int(297) 44int(303) 45int(4667) 46int(-4667) 47int(6844) 48int(1) 49 50-- Try sccanf() WITH optional args -- 51int(6) 52int(297) 53int(303) 54int(4667) 55int(-4667) 56int(6844) 57int(1) 58int(6) 59int(297) 60int(303) 61int(4667) 62int(-4667) 63int(6844) 64int(1) 65===DONE===