Sample code for 30+ languages & platforms
PHP ActiveX

Parse a URL into its Component Parts

See more HTTP Examples

Demonstrates how to parse a URL into it's component parts.

Chilkat PHP ActiveX Downloads

PHP ActiveX
<?php

$success = 0;

$url = new COM("Chilkat.Url");

$urlStr = 'https://www.amazon.com/Anarchy-State-Utopia-Robert-Nozick/dp/0465051006/ref=sr_1_1?s=books&ie=UTF8&qid=1430344305&sr=1-1&keywords=nozick#frag123';

$success = $url->ParseUrl($urlStr);
// Assume success..

print 'URL: ' . $urlStr . "\n";
print 'Host: ' . $url->Host . "\n";
print 'Port: ' . $url->Port . "\n";
print 'HostType: ' . $url->HostType . "\n";
print 'Ssl: ' . $url->Ssl . "\n";
print 'Path: ' . $url->Path . "\n";
print 'Query: ' . $url->Query . "\n";
print 'Frag: ' . $url->Frag . "\n";
print '----' . "\n";

$urlStr = 'http://matt:secret@www.chilkatsoft.com:8080/somepath.asp?test=123&size=2';

$success = $url->ParseUrl($urlStr);
// Assume success..

print 'URL: ' . $urlStr . "\n";
print 'Host: ' . $url->Host . "\n";
print 'Port: ' . $url->Port . "\n";
print 'HostType: ' . $url->HostType . "\n";
print 'Ssl: ' . $url->Ssl . "\n";
print 'Login: ' . $url->Login . "\n";
print 'Password: ' . $url->Password . "\n";
print 'Path: ' . $url->Path . "\n";
print 'Query: ' . $url->Query . "\n";
print 'Frag: ' . $url->Frag . "\n";

?>