PHP sscanf() Function Last Updated : 11 Apr, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The PHP sscanf() is an inbuilt function in PHP where the input string is parsed according to the specified or a particular pattern, along with comparing & matching any whitespace in between the format string & input string, which means, even the tab(\t) will be comparing & matches a single space character in between the format string & input string. Syntax: sscanf(string $input, string $format, mixed &...$vars): array|int|nullParameters: This function accepts three parameters that are described below. $input: This is the input parameter that gets the string parsed.$format: This parameter gets the expected string by using the format like %d is for integer %f for floating point values.&$vars: This parameter specifies one more variable to store extracted values.Return Values: The sscanf() function returns an array when two parameters are passed. This function returns a parsed value in an array otherwise it will return the number of characters. If the error occurs, it will return "null". Example 1: The following code demonstrates the sscanf() function. PHP <?php $str = "10,20"; sscanf($str, "%d,%d", $num1, $num2); echo "Number 1: " . $num1 . "\n"; echo "Number 2: " . $num2 ; ?> Output: Number 1: 10 Number 2: 20 Example 2: The following code demonstrates the sscanf() function. PHP <?php $input_string = "Amit Kumar"; $first_name = ""; $last_name = ""; if (sscanf($input_string, "%s %s", $first_name, $last_name) === 2) { echo "First name: " . $first_name . "\n"; echo "Last name: " . $last_name . "\n"; } ?> Output: First name: Amit Last name: Kumar Reference: https://www.php.net/manual/en/function.sscanf.php Comment More infoAdvertise with us Next Article PHP sizeof() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-string PHP-function Similar Reads PHP sprintf() Function The sprintf() function is an inbuilt function in PHP that is used for formatting strings in a manner similar to the C language's printf() function. It allows you to create formatted strings by substituting placeholders with corresponding values. Syntax: string sprintf(string $format, mixed ...$value 2 min read PHP vsprintf() Function The vsprintf() function in PHP is an inbuilt function and used to display array values as a formatted string. The array elements will be inserted at the percent (%) signs in the main string. Display array values as a formatted string according to its format and accepts an array argument in place of 5 min read PHP strlen() Function The strlen() is a built-in function in PHP which returns the length of a given string.It calculates the length of the string including all the whitespaces and special characters. Syntax:strlen($string);Parameters: This parameter represents the string whose length is needed to be returned. Return Val 1 min read PHP sizeof() Function In this article, we will see how to get the length of the array using the sizeof() function in PHP. The sizeof() function is a built-in function in PHP and is used to count the number of elements present in an array or any other countable object. Syntax: int sizeof(array, mode);Parameter: This funct 2 min read PHP strstr() Function The strstr() function is a built-in function in PHP. It searches for the first occurrence of a string inside another string and displays the portion of the latter starting from the first occurrence of the former in the latter (before if specified). This function is case-sensitive. Syntax : strstr( $ 2 min read PHP String Functions Strings are a fundamental data type in PHP, used to store and manipulate text. PHP provides a wide variety of built-in string functions. These functions perform various operations such as string transformations, character manipulations, encoding and decoding, and formatting, making string handling s 6 min read Like