What potential pitfalls should be considered when trying to extract information about index files from a URL path in PHP?

One potential pitfall when trying to extract information about index files from a URL path in PHP is that the URL structure may vary, leading to inconsistencies in extracting the index file. To solve this, we can use PHP's built-in functions like `parse_url` to extract the path from the URL and then use `basename` to get the filename of the index file.

$url = 'http://www.example.com/index.php';
$path = parse_url($url, PHP_URL_PATH);
$indexFile = basename($path);
echo $indexFile; // Output: index.php