How can PHP developers convert absolute links to relative links for better website maintenance?

When working on a website, it is beneficial to convert absolute links to relative links to improve website maintenance. This can be achieved by using PHP to dynamically generate relative links based on the current page's URL. By doing so, developers can easily update links without having to manually change each absolute link throughout the website.

function convertAbsoluteToRelative($absoluteLink) {
    $baseUrl = $_SERVER['HTTP_HOST'];
    $relativeLink = str_replace($baseUrl, '', $absoluteLink);
    
    return $relativeLink;
}

// Example usage
$absoluteLink = 'http://example.com/page';
$relativeLink = convertAbsoluteToRelative($absoluteLink);
echo $relativeLink; // Output: /page