cvs: php-src /ext/standard/tests/strings sscanf_basic1.phpt sscanf_basic2.phpt sscanf_basic3.phpt sscanf_basic4.phpt sscanf_basic5.phpt
sscanf_basic6.phpt sscanf_basic7.phpt sscanf_basic8.phpt sscanf_error.phpt sscanf_variation1.phpt sscanf_variation2.phpt

From: Date: Sun, 18 Jan 2009 14:40:25 +0000
Subject: cvs: php-src /ext/standard/tests/strings sscanf_basic1.phpt sscanf_basic2.phpt sscanf_basic3.phpt sscanf_basic4.phpt sscanf_basic5.phpt
sscanf_basic6.phpt sscanf_basic7.phpt sscanf_basic8.phpt sscanf_error.phpt sscanf_variation1.phpt sscanf_variation2.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-55718@lists.php.net to get a copy of this message
wharmby Sun Jan 18 14:40:25 2009 UTC Modified files: /php-src/ext/standard/tests/strings sscanf_basic4.phpt sscanf_variation2.phpt sscanf_basic6.phpt sscanf_basic8.phpt sscanf_error.phpt sscanf_basic2.phpt sscanf_basic5.phpt sscanf_variation1.phpt sscanf_basic7.phpt sscanf_basic3.phpt sscanf_basic1.phpt Log: New sscanf() tests. Tested on Windows. Linux and Linux 64 bit

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_basic4.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_basic4.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_basic4.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_basic4.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,43 @@ +--TEST-- +Test sscanf() function : basic functionality - char format +--FILE-- +<?php + +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +echo "*** Testing sscanf() : basic functionality - using char format ***\n"; + +$str = "X = A + B - C"; +$format = "%c = %c + %c - %c"; + +echo "\n-- Try sccanf() WITHOUT optional args --\n"; +// extract details using short format +list($arg1, $arg2, $arg3, $arg4) = sscanf($str, $format); +var_dump($arg1, $arg2, $arg3, $arg4); + +echo "\n-- Try sccanf() WITH optional args --\n"; +// extract details using long format +$res = sscanf($str, $format, $arg1, $arg2, $arg3, $arg4); +var_dump($res, $arg1, $arg2, $arg3, $arg4); + +?> +===DONE=== +--EXPECT-- +*** Testing sscanf() : basic functionality - using char format *** + +-- Try sccanf() WITHOUT optional args -- +unicode(1) "X" +unicode(1) "A" +unicode(1) "B" +unicode(1) "C" + +-- Try sccanf() WITH optional args -- +int(4) +unicode(1) "X" +unicode(1) "A" +unicode(1) "B" +unicode(1) "C" +===DONE=== \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_variation2.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_variation2.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_variation2.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_variation2.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,153 @@ +--TEST-- +Test sscanf() function : usage variations - unexpected inputs for '$format' argument +--FILE-- +<?php +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +echo "*** Testing sscanf() function: with unexpected inputs for 'format' argument ***\n"; + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +//getting the resource +$file_handle = fopen(__FILE__, "r"); + +// array with different values for $input +$inputs = array ( + + // integer values +/*1*/ 0, + 1, + -2, + 2147483647, + -2147483648, + + // float values +/*6*/ 10.5, + -20.5, + 10.1234567e10, + + // array values +/*9*/ array(), + array(0), + array(1, 2), + + // boolean values +/*12*/ true, + false, + TRUE, + FALSE, + + // null values +/*16*/ NULL, + null, + + // objects +/*18*/ new sample(), + + // resource +/*19*/ $file_handle, + + // undefined variable +/*20*/ @$undefined_var, + + // unset variable +/*21*/ @$unset_var +); + +//defining '$pad_length' argument +$str = "Hello World"; + +// loop through with each element of the $inputs array to test sscanf() function +$count = 1; +foreach($inputs as $input) { + echo "-- Iteration $count --\n"; + var_dump( sscanf($str, $input) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing sscanf() function: with unexpected inputs for 'format' argument *** +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(0) { +} +-- Iteration 3 -- +array(0) { +} +-- Iteration 4 -- +array(0) { +} +-- Iteration 5 -- +array(0) { +} +-- Iteration 6 -- +array(0) { +} +-- Iteration 7 -- +array(0) { +} +-- Iteration 8 -- +array(0) { +} +-- Iteration 9 -- + +Warning: sscanf() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: sscanf() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: sscanf() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 12 -- +array(0) { +} +-- Iteration 13 -- +array(0) { +} +-- Iteration 14 -- +array(0) { +} +-- Iteration 15 -- +array(0) { +} +-- Iteration 16 -- +array(0) { +} +-- Iteration 17 -- +array(0) { +} +-- Iteration 18 -- +array(0) { +} +-- Iteration 19 -- + +Warning: sscanf() expects parameter 2 to be string (Unicode or binary), resource given in %s on line %d +NULL +-- Iteration 20 -- +array(0) { +} +-- Iteration 21 -- +array(0) { +} +===DONE=== \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_basic6.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_basic6.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_basic6.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_basic6.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,47 @@ +--TEST-- +Test sscanf() function : basic functionality - unsigned format +--FILE-- +<?php + +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +echo "*** Testing sscanf() : basic functionality - using unsigned format ***\n"; + +$str = "-11 +11 11 -11.234 +11.234 11.234"; +$format = "%u %u %u %u %u %u"; + +echo "\n-- Try sccanf() WITHOUT optional args --\n"; +// extract details using short format +list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format); +var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); + +echo "\n-- Try sccanf() WITH optional args --\n"; +// extract details using long format +$res = sscanf($str, $format, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); +var_dump($res, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); + +?> +===DONE=== +--EXPECT-- +*** Testing sscanf() : basic functionality - using unsigned format *** + +-- Try sccanf() WITHOUT optional args -- +unicode(10) "4294967285" +int(11) +int(11) +unicode(10) "4294967285" +NULL +NULL + +-- Try sccanf() WITH optional args -- +int(4) +unicode(10) "4294967285" +int(11) +int(11) +unicode(10) "4294967285" +NULL +NULL +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_basic8.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_basic8.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_basic8.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_basic8.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,65 @@ +--TEST-- +Test sscanf() function : basic functionality - hexadecimal format +--FILE-- +<?php + +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +echo "*** Testing sscanf() : basic functionality - - using hexadecimal format ***\n"; + +$str = "129 12F 123B -123B 01ABC 1G"; +$format1 = "%x %x %x %x %x %x"; +$format2 = "%X %X %X %X %X %X"; + +echo "\n-- Try sccanf() WITHOUT optional args --\n"; +// extract details using short format +list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format1); +var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); +list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format2); +var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); + +echo "\n-- Try sccanf() WITH optional args --\n"; +// extract details using long format +$res = sscanf($str, $format1, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); +var_dump($res, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); +$res = sscanf($str, $format2, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); +var_dump($res, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); + +?> +===DONE=== +--EXPECT-- +*** Testing sscanf() : basic functionality - - using hexadecimal format *** + +-- Try sccanf() WITHOUT optional args -- +int(297) +int(303) +int(4667) +int(-4667) +int(6844) +int(1) +int(297) +int(303) +int(4667) +int(-4667) +int(6844) +int(1) + +-- Try sccanf() WITH optional args -- +int(6) +int(297) +int(303) +int(4667) +int(-4667) +int(6844) +int(1) +int(6) +int(297) +int(303) +int(4667) +int(-4667) +int(6844) +int(1) +===DONE=== \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_error.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_error.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_error.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,44 @@ +--TEST-- +Test sscanf() function : error conditions +--FILE-- +<?php + +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ +echo "*** Testing sscanf() : error conditions ***\n"; + +$str = "Hello World"; +$format = "%s %s"; + +echo "\n-- Testing sscanf() function with no arguments --\n"; +var_dump( sscanf() ); + +echo "\n-- Testing sscanf() function with one argument --\n"; +var_dump( sscanf($str) ); + +echo "\n-- Testing sscanf() function with more than expected no. of arguments --\n"; + +var_dump( sscanf($str, $format, $str1, $str2, $extra_str) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing sscanf() : error conditions *** + +-- Testing sscanf() function with no arguments -- + +Warning: sscanf() expects at least 2 parameters, 0 given in %s on line %d +NULL + +-- Testing sscanf() function with one argument -- + +Warning: sscanf() expects at least 2 parameters, 1 given in %s on line %d +NULL + +-- Testing sscanf() function with more than expected no. of arguments -- + +Warning: sscanf(): Variable is not assigned by any conversion specifiers in %s on line %d +int(-1) +===DONE=== \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_basic2.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_basic2.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_basic2.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_basic2.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,44 @@ +--TEST-- +Test sscanf() function : basic functionality - integer format +--FILE-- +<?php +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +/* + * Testing sscanf() : basic functionality +*/ + +echo "*** Testing sscanf() : basic functionality - using integer format ***\n"; + +$str = "Part: Widget Serial Number: 1234789 Stock: 25"; +$format = "Part: %s Serial Number: %d Stock: %d"; + +echo "\n-- Try sccanf() WITHOUT optional args --\n"; +// extract details using short format +list($part, $number, $stock) = sscanf($str, $format); +var_dump($part, $number, $stock); + +echo "\n-- Try sccanf() WITH optional args --\n"; +// extract details using long format +$res = sscanf($str, $format, $part, $number, $stock); +var_dump($res, $part, $number, $stock); + +?> +===DONE=== +--EXPECT-- +*** Testing sscanf() : basic functionality - using integer format *** + +-- Try sccanf() WITHOUT optional args -- +unicode(6) "Widget" +int(1234789) +int(25) + +-- Try sccanf() WITH optional args -- +int(3) +unicode(6) "Widget" +int(1234789) +int(25) +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_basic5.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_basic5.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_basic5.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_basic5.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,58 @@ +--TEST-- +Test sscanf() function : basic functionality - exponential format +--FILE-- +<?php + +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +echo "*** Testing sscanf() : basic functionality -using exponential format ***\n"; + +$str = "10.12345 10.12345E3 10.12345e3 -10.12345e4" ; +$format1 = "%e %e %e %e"; +$format2 = "%E %E %E %E"; + +echo "\n-- Try sccanf() WITHOUT optional args --\n"; +// extract details using short format +list($arg1, $arg2, $arg3, $arg4) = sscanf($str, $format1); +var_dump($arg1, $arg2, $arg3, $arg4); +list($arg1, $arg2, $arg3, $arg4) = sscanf($str, $format2); +var_dump($arg1, $arg2, $arg3, $arg4); + +echo "\n-- Try sccanf() WITH optional args --\n"; +// extract details using long format +$res = sscanf($str, $format1, $arg1, $arg2, $arg3, $arg4); +var_dump($res, $arg1, $arg2, $arg3, $arg4); +$res = sscanf($str, $format2,$arg1, $arg2, $arg3, $arg4); +var_dump($res, $arg1, $arg2, $arg3, $arg4); + + +?> +===DONE=== +--EXPECT-- +*** Testing sscanf() : basic functionality -using exponential format *** + +-- Try sccanf() WITHOUT optional args -- +float(10.12345) +float(10123.45) +float(10123.45) +float(-101234.5) +float(10.12345) +float(10123.45) +float(10123.45) +float(-101234.5) + +-- Try sccanf() WITH optional args -- +int(4) +float(10.12345) +float(10123.45) +float(10123.45) +float(-101234.5) +int(4) +float(10.12345) +float(10123.45) +float(10123.45) +float(-101234.5) +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_variation1.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_variation1.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_variation1.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_variation1.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,169 @@ +--TEST-- +Test sscanf() function : usage variations - unexpected inputs for '$str' argument +--FILE-- +<?php +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +echo "*** Testing sscanf() function: with unexpected inputs for 'str' argument ***\n"; + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +//getting the resource +$file_handle = fopen(__FILE__, "r"); + +// array with different values for $input +$inputs = array ( + + // integer values +/*1*/ 0, + 1, + -2, + 2147483647, + -2147483648, + + // float values +/*6*/ 10.5, + -20.5, + 10.1234567e10, + + // array values +/*9*/ array(), + array(0), + array(1, 2), + + // boolean values +/*12*/ true, + false, + TRUE, + FALSE, + + // null values +/*16*/ NULL, + null, + + // objects +/*18*/ new sample(), + + // resource +/*19*/ $file_handle, + + // undefined variable +/*20*/ @$undefined_var, + + // unset variable +/*21*/ @$unset_var +); + +//defining '$pad_length' argument +$format = "%s"; + +// loop through with each element of the $inputs array to test sscanf() function +$count = 1; +foreach($inputs as $input) { + echo "-- Iteration $count --\n"; + var_dump( sscanf($input, $format) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing sscanf() function: with unexpected inputs for 'str' argument *** +-- Iteration 1 -- +array(1) { + [0]=> + unicode(1) "0" +} +-- Iteration 2 -- +array(1) { + [0]=> + unicode(1) "1" +} +-- Iteration 3 -- +array(1) { + [0]=> + unicode(2) "-2" +} +-- Iteration 4 -- +array(1) { + [0]=> + unicode(10) "2147483647" +} +-- Iteration 5 -- +array(1) { + [0]=> + unicode(11) "-2147483648" +} +-- Iteration 6 -- +array(1) { + [0]=> + unicode(4) "10.5" +} +-- Iteration 7 -- +array(1) { + [0]=> + unicode(5) "-20.5" +} +-- Iteration 8 -- +array(1) { + [0]=> + unicode(12) "101234567000" +} +-- Iteration 9 -- + +Warning: sscanf() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: sscanf() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: sscanf() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 12 -- +array(1) { + [0]=> + unicode(1) "1" +} +-- Iteration 13 -- +NULL +-- Iteration 14 -- +array(1) { + [0]=> + unicode(1) "1" +} +-- Iteration 15 -- +NULL +-- Iteration 16 -- +NULL +-- Iteration 17 -- +NULL +-- Iteration 18 -- +array(1) { + [0]=> + unicode(6) "sample" +} +-- Iteration 19 -- + +Warning: sscanf() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d +NULL +-- Iteration 20 -- +NULL +-- Iteration 21 -- +NULL +===DONE=== \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_basic7.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_basic7.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_basic7.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_basic7.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,47 @@ +--TEST-- +Test sscanf() function : basic functionality - octal format +--FILE-- +<?php + +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +echo "*** Testing sscanf() : basic functionality - using octal format ***\n"; + +$str = "0123 -0123 +0123 0129 -0129 +0129"; +$format = "%o %o %o %o %o %o"; + +echo "\n-- Try sccanf() WITHOUT optional args --\n"; +// extract details using short format +list($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) = sscanf($str, $format); +var_dump($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); + +echo "\n-- Try sccanf() WITH optional args --\n"; +// extract details using long format +$res = sscanf($str, $format, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); +var_dump($res, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); + +?> +===DONE=== +--EXPECT-- +*** Testing sscanf() : basic functionality - using octal format *** + +-- Try sccanf() WITHOUT optional args -- +int(83) +int(-83) +int(83) +int(10) +NULL +NULL + +-- Try sccanf() WITH optional args -- +int(4) +int(83) +int(-83) +int(83) +int(10) +NULL +NULL +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_basic3.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_basic3.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_basic3.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_basic3.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,43 @@ +--TEST-- +Test sscanf() function : basic functionality - float format +--FILE-- +<?php + +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +echo "*** Testing sscanf() : basic functionality -- using float format ***\n"; + +$str = "Part: Widget Length: 111.53 Width: 22.345 Depth: 12.4"; +$format = "Part: %s Length: %f Width: %f Depth: %f"; + +echo "\n-- Try sccanf() WITHOUT optional args --\n"; +// extract details using short format +list($part, $length, $width, $depth) = sscanf($str, $format); +var_dump($part, $length, $width, $depth); + +echo "\n-- Try sccanf() WITH optional args --\n"; +// extract details using long format +$res = sscanf($str, $format, $part, $length, $width, $depth); +var_dump($res, $part, $length, $width, $depth); + +?> +===DONE=== +--EXPECT-- +*** Testing sscanf() : basic functionality -- using float format *** + +-- Try sccanf() WITHOUT optional args -- +unicode(6) "Widget" +float(111.53) +float(22.345) +float(12.4) + +-- Try sccanf() WITH optional args -- +int(4) +unicode(6) "Widget" +float(111.53) +float(22.345) +float(12.4) +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sscanf_basic1.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/sscanf_basic1.phpt diff -u /dev/null php-src/ext/standard/tests/strings/sscanf_basic1.phpt:1.2 --- /dev/null Sun Jan 18 14:40:25 2009 +++ php-src/ext/standard/tests/strings/sscanf_basic1.phpt Sun Jan 18 14:40:25 2009 @@ -0,0 +1,44 @@ +--TEST-- +Test sscanf() function : basic functionality - string format +--FILE-- +<?php +/* Prototype : mixed sscanf ( string $str , string $format [, mixed &$... ] ) + * Description: Parses input from a string according to a format + * Source code: ext/standard/string.c +*/ + +/* + * Testing sscanf() : basic functionality +*/ + +echo "*** Testing sscanf() : basic functionality - using string format ***\n"; + +$str = "Part: Widget Serial Number: 1234789 Stock: 25"; +$format = "Part: %s Serial Number: %s Stock: %s"; + +echo "\n-- Try sccanf() WITHOUT optional args --\n"; +// extract details using short format +list($part, $number, $stock) = sscanf($str, $format); +var_dump($part, $number, $stock); + +echo "\n-- Try sccanf() WITH optional args --\n"; +// extract details using long format +$res = sscanf($str, $format, $part, $number, $stock); +var_dump($res, $part, $number, $stock); + +?> +===DONE=== +--EXPECT-- +*** Testing sscanf() : basic functionality - using string format *** + +-- Try sccanf() WITHOUT optional args -- +unicode(6) "Widget" +unicode(7) "1234789" +unicode(2) "25" + +-- Try sccanf() WITH optional args -- +int(3) +unicode(6) "Widget" +unicode(7) "1234789" +unicode(2) "25" +===DONE===
« previous php.cvs (#55718) next »