What are the advantages of using the `parse_url` function in PHP for handling URLs compared to manual string manipulation?

When handling URLs in PHP, using the `parse_url` function is advantageous compared to manual string manipulation because it provides a reliable and standardized way to extract various components of a URL such as the scheme, host, path, query, and fragment. This function simplifies the process of working with URLs, reduces the chances of errors, and improves code readability.

$url = "https://www.example.com/path/to/page?query=123";

$parsed_url = parse_url($url);

echo "Scheme: " . $parsed_url['scheme'] . "\n";
echo "Host: " . $parsed_url['host'] . "\n";
echo "Path: " . $parsed_url['path'] . "\n";
echo "Query: " . $parsed_url['query'] . "\n";