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