How can the explode() function in PHP be utilized to convert date entries from one format to another, such as from "050507" to "2005-05-07"?

To convert date entries from one format to another, such as from "050507" to "2005-05-07", you can use the explode() function in PHP to split the original date string into day, month, and year components. Then, you can concatenate these components in the desired format to create the new date string.

$date = "050507";
$day = substr($date, 0, 2);
$month = substr($date, 2, 2);
$year = "20" . substr($date, 4, 2);

$new_date = $year . "-" . $month . "-" . $day;
echo $new_date; // Output: 2005-05-07