What is the function used to convert a string to a specific date format in PHP?

To convert a string to a specific date format in PHP, you can use the `DateTime` class along with the `createFromFormat()` method. This method allows you to create a new `DateTime` object from a string formatted in a specific way. By specifying the format of the input string, you can ensure that it is parsed correctly and converted to the desired date format.

// Input string in a specific format
$inputString = '2022-12-31';

// Specify the format of the input string
$inputFormat = 'Y-m-d';

// Create a new DateTime object from the input string
$date = DateTime::createFromFormat($inputFormat, $inputString);

// Convert the date to a specific format
$outputFormat = 'F j, Y';
$outputDateString = $date->format($outputFormat);

// Output the converted date string
echo $outputDateString;