Return to sscanf_basic8.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test 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: 11: echo "*** 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: 17: echo "\n-- Try sccanf() WITHOUT optional args --\n"; 18: // extract details using short format 19: list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format1); 20: var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 21: list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format2); 22: var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 23: 24: echo "\n-- Try sccanf() WITH optional args --\n"; 25: // extract details using long format 26: $res = sscanf($str, $format1, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 27: var_dump($res, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 28: $res = sscanf($str, $format2, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); 29: var_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 -- 37: int(297) 38: int(303) 39: int(4667) 40: int(-4667) 41: int(6844) 42: int(1) 43: int(297) 44: int(303) 45: int(4667) 46: int(-4667) 47: int(6844) 48: int(1) 49: 50: -- Try sccanf() WITH optional args -- 51: int(6) 52: int(297) 53: int(303) 54: int(4667) 55: int(-4667) 56: int(6844) 57: int(1) 58: int(6) 59: int(297) 60: int(303) 61: int(4667) 62: int(-4667) 63: int(6844) 64: int(1) 65: ===DONE===