$url = "https://www.example.com/some/page.html"; $domain = parse_url($url, PHP_URL_HOST); echo $domain; // Output: "www.example.com"
$path = "/path/to/file.txt"; $extension = pathinfo($path, PATHINFO_EXTENSION); echo $extension; // Output: "txt"
$url = "https://www.example.com/search?q=example&limit=10"; $parameters = parse_url($url, PHP_URL_QUERY); parse_str($parameters, $output); var_dump($output); // Output: // array(2) { // ["q"]=> // string(7) "example" // ["limit"]=> // string(2) "10" // }
$url = "https://www.example.com/search?q=example&limit=10"; $parameters = parse_url($url, PHP_URL_QUERY); parse_str($parameters, $output); echo $output["q"]; // Output: "example"Package Library: Standard Library Overall, `getComponent` is a useful function for working with strings and URLs in PHP. It can be used in a variety of situations to extract specific components from a larger text or URL.