In PHP, what functions or methods can be used to format numerical values with leading zeros, such as converting "2b" to "02b" for image file names?

When dealing with numerical values that need to be formatted with leading zeros, such as converting "2b" to "02b" for image file names, the str_pad() function in PHP can be used. This function pads a string to a certain length with another string (in this case, "0") at the beginning. By specifying the desired total length and the padding character, we can easily achieve the desired formatting.

$num = "2b";
$length = 3;
$padded_num = str_pad($num, $length, "0", STR_PAD_LEFT);

echo $padded_num; // Output: 02b