note 86413 modified in function.parse-url by danbrown

From: Date: Fri, 17 Oct 2008 13:31:25 +0000
Subject: note 86413 modified in function.parse-url by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145451@lists.php.net to get a copy of this message
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; } ?> --was-- 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; } http://php.net/manual/en/function.parse-url.php

« previous php.notes (#145451) next »