Voting

: max(six, two)?
(Example: nine)

The Note You're Voting On

vdklah at hotmail dot com
16 years ago
Some example that determines the URL port.
When port not specified, it derives it from the scheme.

<?php
function getUrlPort( $urlInfo )
{
if( isset(
$urlInfo['port']) ) {
$port = $urlInfo['port'];
} else {
// no port specified; get default port
if (isset($urlInfo['scheme']) ) {
switch(
$urlInfo['scheme'] ) {
case
'http':
$port = 80; // default for http
break;
case
'https':
$port = 443; // default for https
break;
case
'ftp':
$port = 21; // default for ftp
break;
case
'ftps':
$port = 990; // default for ftps
break;
default:
$port = 0; // error; unsupported scheme
break;
}
} else {
$port = 0; // error; unknown scheme
}
}
return
$port;
}

$url = "http://nl3.php.net/manual/en/function.parse-url.php";
$urlInfo = parse_url( $url );
$urlPort = getUrlPort( $urlInfo );
if(
$urlPort !== 0 ) {
print
'Found URL port: '.$urlPort;
} else {
print
'ERROR: Could not find port at URL: '.$url;
}
?>

<< Back to user notes page

To Top