") { if (is_array($val)) { for ($i = 0;$i< count($val);$i++) { echo $val[$i] . $postfix; } } else { echo $val . $postfix; } } function do_sscanf($string, $format) { $s = "sscanf(\"" . $string . ",\"" . $format ."\")."; echo "$s
"; $s = str_repeat("-", strlen($s)); echo "$s
"; $output = sscanf($string,$format); echo "Result : "; print_value( $output ); echo "$s

"; } function run_sscanf_test_cases($filename="scan_cases") { echo "


Running Test Cases from $filename

"; $arr = file($filename); for ($i=0;$i < count($arr);$i++) { $line_arr = explode("|",$arr[$i]); $format = $line_arr[0]; $string = $line_arr[1]; if (count($arr) > 2) { $comment = $line_arr[2]; } else { $comment = ""; } if ( empty($format) || empty($string) ) { continue; } print("

** Case : $comment ******************************

"); do_sscanf($string,$format); } } function simple_tests() { echo "Testing sscanf with standard ANSI syntax (values returned by reference)-
"; $decimal = -1; $string = ""; $hex = 0; $float = 0.0; $octal = 0.0; $int = -1; echo "


Simple Test

"; echo "sscanf('10','%d',&\$decimal)
"; echo "
BEFORE :
decimal = $decimal."; $foo = sscanf("10","%d",&$decimal); echo "
AFTER :
decimal = $decimal
"; echo "


Simple Test 2

"; echo "sscanf(\"ghost 0xface\",\"%s %x\",&\$string, &\$int)
"; echo "
BEFORE :
string = $string, int = $int
"; $foo = sscanf("ghost 0xface","%s %x",&$string, &$int); echo "
AFTER :
string = $string, int = $int
"; echo " sscan reports : "; print_value( $foo,""); echo " conversions
"; echo "


Multiple specifiers

"; echo "sscanf(\"jabberwocky 1024 0xFF 1.024 644 10\", \"%s %d %x %f %o %i\", &\$string,&\$decimal,&\$hex,&\$float,&\$octal,&\$int);
"; echo "
BEFORE :
"; echo "Decimal = $decimal, String = $string, Hex = $hex
"; echo "Octal = $octal , Float = $float, Int = $int
"; $foo = sscanf( "jabberwocky 1024 0xFF 1.024 644 10", "%s %d %x %f %o %i", &$string,&$decimal,&$hex,&$float,&$octal,&$int); echo "
AFTER :
"; echo "decimal = $decimal, string = $string, hex = $hex
"; echo "octal = $octal , float = $float, int = $int
"; echo " sscan reports : "; print_value( $foo,""); echo " conversions
"; echo "----------------------------------------
"; } ?> Test of sscanf()

Testing sscanf() support in PHP


I'm sorry but sscanf() does not exist !i
"; } else { simple_tests(); run_sscanf_test_cases(); } ?>