How can the domain and subdirectories be captured from a URL using PHP?

To capture the domain and subdirectories from a URL using PHP, you can use the parse_url() function to extract the necessary components. The "host" key will give you the domain, and the "path" key will give you the subdirectories.

$url = "https://www.example.com/subdirectory/page.html";
$parsed_url = parse_url($url);
$domain = $parsed_url['host'];
$subdirectories = $parsed_url['path'];
echo "Domain: $domain\n";
echo "Subdirectories: $subdirectories\n";