Sample code for 30+ languages & platforms
PHP

Parse a URL into its Component Parts

See more HTTP Examples

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

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Url;

$url = new 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';

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

echo 'URL: ', $urlStr, "\n";
echo 'Host: ', $url->Host, "\n";
echo 'Port: ', $url->Port, "\n";
echo 'HostType: ', $url->HostType, "\n";
echo 'Ssl: ', ($url->Ssl ? 'true' : 'false'), "\n";
echo 'Path: ', $url->Path, "\n";
echo 'Query: ', $url->Query, "\n";
echo 'Frag: ', $url->Frag, "\n";
echo "----\n";

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

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

echo 'URL: ', $urlStr, "\n";
echo 'Host: ', $url->Host, "\n";
echo 'Port: ', $url->Port, "\n";
echo 'HostType: ', $url->HostType, "\n";
echo 'Ssl: ', ($url->Ssl ? 'true' : 'false'), "\n";
echo 'Login: ', $url->Login, "\n";
echo 'Password: ', $url->Password, "\n";
echo 'Path: ', $url->Path, "\n";
echo 'Query: ', $url->Query, "\n";
echo 'Frag: ', $url->Frag, "\n";