PHP 8.5.0 Alpha 1 available for testing

Voting

: eight plus one?
(Example: nine)

The Note You're Voting On

plasma
15 years ago
To extract scheme, host, path, ect. simply use

<?php

$url
= 'http://name:pass@';
$url .= 'example.com:10000';
$url .= '/path/to/file.php?a=1&amp;b=2#anchor';

$url_data = parse_url ( $url );

print_r ( $url_data );

?>
___
prints out something like:

Array
(
[scheme] => http
[host] => wild.subdomain.orgy.domain.co.uk
[port] => 10000
[user] => name
[pass] => pass
[path] => /path/to/file.php
[query] => a=1&b=2
[fragment] => anchor
)

In my tests parse_url is up to 15x faster than preg_match(_all)!

<< Back to user notes page

To Top