Example 1 — Read Numbers from a Date
Pull the year, month, and day out of a string.
<?php
list($year, $month, $day) = sscanf("2026-11-11", "%d-%d-%d");
echo "Year: ", $year, PHP_EOL;
echo "Month: ", $month, PHP_EOL;
echo "Day: ", $day, PHP_EOL; How It Works
- Write a matching format. Each
%dreads a whole number. - Keep the dashes. Plain characters must match the input.
- Get an array.
list()splits it into three variables. - Print the parts. Each value is already an integer.

