PHP sscanf function
The PHP sscanf function can parse a string variable according to the specified format and format the parsed part, that is to say, you can use the sscanf function to parse and read some parts of a string , and then Process according to the virtual format, and finally obtain the required string data. The effect is opposite to the functions such as printf and sprintf . Although all the actions of formatting strings are processed through regular expressions , functions such as printf and sprintf Insert characters into the string , and the sscanf function parses the characters from the string .
Basic syntax of PHP sscanf function
mixed sscanf ($string, $format, $args1, $args2, $args3, $args4 ...)
sscanf function within parentheses first $ string argument to the original string , which is about to read is parsed string , the second parameter $ format is the format you want to use, sscanf function based on $ format format , Parse the $string string , and store the parsed result through the third starting $args. For the conversion format of $format, please refer to the parameter table on the sprintf function . Note that the sscanf function does not support F, g, G, b and other formats. The two parameters $string and $format are required items. The storage parameters of $args at the back are optional items and the number is determined by yourself. However, if the percentage (%) in the $format parameter exceeds the number of $args, an error message will appear.
PHP sscanf function example
$string = "This is float 3.2 and this is integer 8";
sscanf($string,"This is float %f and this is integer %d",$float,$integer);
var_dump($float,$ integer);
?>
Post a Comment
0 Comments