How can the concept of a base URL be implemented in PHP to generate web paths for links in HTML without relying on file system paths?

When generating web paths for links in HTML using PHP, it's important to use a base URL to ensure that the links work correctly regardless of the file system paths. One way to implement this is by defining a base URL variable in your PHP code and then using this variable to construct the web paths for links.

<?php
// Define the base URL
$base_url = "http://www.example.com/";

// Generate web paths for links using the base URL
$link1 = $base_url . "page1.php";
$link2 = $base_url . "page2.php";

// Output the links in HTML
echo "<a href='$link1'>Page 1</a><br>";
echo "<a href='$link2'>Page 2</a>";
?>