What are some alternative methods for implementing breadcrumb navigation in PHP without organizing files in separate folders?

When implementing breadcrumb navigation in PHP without organizing files in separate folders, one alternative method is to dynamically generate breadcrumbs based on the current URL structure. This can be achieved by parsing the URL and creating breadcrumb links for each segment.

<?php
// Get the current URL
$current_url = $_SERVER['REQUEST_URI'];

// Split the URL into segments
$url_segments = explode('/', trim($current_url, '/'));

// Initialize an empty array for breadcrumbs
$breadcrumbs = [];

// Loop through each segment and create breadcrumb links
$breadcrumb_path = '';
foreach ($url_segments as $segment) {
    $breadcrumb_path .= '/' . $segment;
    $breadcrumbs[] = '<a href="' . $breadcrumb_path . '">' . ucfirst($segment) . '</a>';
}

// Output the breadcrumbs
echo implode(' > ', $breadcrumbs);
?>