Great little php URL parser

Posted on

You can get varied results with parse_url in php. This class gets great results, check it out:
https://github.com/monkeysuffrage/phpuri

Example

require 'phpuri.php';
$uri = phpUri::parse('https://www.google.com/foo?q=bar');
echo $uri->scheme;
echo $uri->authority;
echo $uri->path;
echo $uri->query;
//==> https://
//==> google.com
//==> foo
//==> ?q=bar

Benchmarks

rel2abs:         successes -> 26, fails => 9, time: 0.001301
url_to_absolute: successes -> 32, fails => 3, time: 0.0029089999999999
phpuri:          successes -> 35, fails => 0, time: 0.002402

Leave a Reply

Your email address will not be published.