passort not matchwhy not什么意思思

The passwords do not match什么意思饿_百度知道
The passwords do not match什么意思饿
提问者采纳
密码不匹配.The passwords do not matchThe passwords do not match密码不匹配双语对照例句. Please retype the password. Please try again.The passwords do not match. 密码不匹配。请再试一次。 2:1
来自团队:
其他类似问题
为您推荐:
match的相关知识
其他2条回答
密码不匹配采纳我哟
密码不匹配,,,
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Keyboard Shortcuts?
Next menu item
Previous menu item
Previous man page
Next man page
Scroll to bottom
Scroll to top
Goto homepage
Goto search(current page)
Focus search box
Change language:
Brazilian Portuguese
Chinese (Simplified)
parse_url & Analyse une URL et retourne ses composants
Description
( string $url
[, int $component = -1
Cette fonction n'est pas
faite pour valider l'URL fournie, elle ne fait que la découper en parties listées
ci-dessous. Les URL partielles sont également acceptées, la fonction
parse_url() fera de son mieux pour les analyser correctement.
Liste de paramètres
L'URL à analyser. Les caractères invalides sont remplacés par
des caractères soulignés _.
Peut être une des constantes parmi PHP_URL_SCHEME,
PHP_URL_HOST, PHP_URL_PORT,
PHP_URL_USER, PHP_URL_PASS,
PHP_URL_PATH, PHP_URL_QUERY
ou PHP_URL_FRAGMENT pour récupérer uniquement
une partie de l'URL en tant que cha?ne de caractères (sauf lorsque
PHP_URL_PORT dans ce cas, la valeur retournée
sera un ).
Valeurs de retour
Pour les URL vraiment mal formées, parse_url() peut retourner
Si le paramètre component est omis, un
associatif est retourné. Au moins un élément sera présent dans le tableau. Voici
les clés potentielles de ce tableau:
scheme - e.g. http
query - après le point d'interrogation &?&
fragment - après le croisillon (dièse) &#&
Si le paramètre component est spécifié, parse_url()
retourne une
dans le cas d'utilisation de la
constante PHP_URL_PORT)au lieu d'un . Si le composent
demandé n'existe pas dans l'URL, NULL sera retourné.
Historique
Exemple #1 Exemple avec parse_url()
&?php$url&=&'http://username:password@hostname:9090/path?arg=value#anchor';var_dump(parse_url($url));var_dump(parse_url($url,&PHP_URL_SCHEME));var_dump(parse_url($url,&PHP_URL_USER));var_dump(parse_url($url,&PHP_URL_PASS));var_dump(parse_url($url,&PHP_URL_HOST));var_dump(parse_url($url,&PHP_URL_PORT));var_dump(parse_url($url,&PHP_URL_PATH));var_dump(parse_url($url,&PHP_URL_QUERY));var_dump(parse_url($url,&PHP_URL_FRAGMENT));?&
L'exemple ci-dessus va afficher :
array(8) {
[&scheme&]=&
string(4) &http&
[&host&]=&
string(8) &hostname&
[&port&]=&
[&user&]=&
string(8) &username&
[&pass&]=&
string(8) &password&
[&path&]=&
string(5) &/path&
[&query&]=&
string(9) &arg=value&
[&fragment&]=&
string(6) &anchor&
string(4) &http&
string(8) &username&
string(8) &password&
string(8) &hostname&
string(5) &/path&
string(9) &arg=value&
string(6) &anchor&
Exemple #2 Exemple avec la fonction parse_url() sans schéma
&?php$url&=&'///path?googleguy=googley';//&Avant&PHP&5.4.7,&le&chemin&sera&"///path"var_dump(parse_url($url));?&
L'exemple ci-dessus va afficher :
array(3) {
[&host&]=&
string(15) &&
[&path&]=&
string(5) &/path&
[&query&]=&
string(17) &googleguy=googley&
Cette fonction ne fonctionne pas avec les URLs relatives.
parse_url() a été créée tout spécialement pour analyser les URL
et non les URI. Cependant, pour des raisons de compatibilité adjacente, PHP
fait une exception pour le schéma file:// où les triples slashs
(file:///...) sont autorisés. Tous les autres schémas sont invalides.
Voir aussi
- Retourne des informations sur un chemin syst&me
- Analyse une requ&te HTTP
- G&n&re une cha&ne de requ&te en encodage URL
- Construit une URL
- Renvoie le chemin du dossier parent
- Retourne le nom du fichier dans un chemin
[If you haven't yet] been able to find a simple conversion back to string from a parsed url, here's an example:
$url = '';
if ($url === unparse_url(parse_url($url))) {
& print "YES, they match!\n";
}
function unparse_url($parsed_url) {
& $scheme&& = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
& $host& && = isset($parsed_url['host']) ? $parsed_url['host'] : '';
& $port& && = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
& $user& && = isset($parsed_url['user']) ? $parsed_url['user'] : '';
& $pass& && = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']& : '';
& $pass& && = ($user || $pass) ? "$pass@" : '';
& $path& && = isset($parsed_url['path']) ? $parsed_url['path'] : '';
& $query& & = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
& $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
& return "$scheme$user$pass$host$port$path$query$fragment";
}
An update to the function by FredLudd at gmail dot com.& I added IPv6 functionality as well.&?phpfunction j_parseUrl($url) {& $r& = "(?:([a-z0-9+-._]+)://)?";& $r .= "(?:";& $r .=&& "(?:((?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9a-f]{2})*)@)?";& $r .=&& "(?:\[((?:[a-z0-9:])*)\])?";& $r .=&& "((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9a-f]{2})*)";& $r .=&& "(?::(\d*))?";& $r .=&& "(/(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9a-f]{2})*)?";& $r .=&& "|";& $r .=&& "(/?";& $r .=& && "(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+";& $r .=& && "(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9a-f]{2})*";& $r .=& & ")?";& $r .= ")";& $r .= "(?:\?((?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9a-f]{2})*))?";& $r .= "(?:#((?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9a-f]{2})*))?";& preg_match("`$r`i", $url, $match);& $parts = array(& & & & & & "scheme"=&'',& & & & & & "userinfo"=&'',& & & & & & "authority"=&'',& & & & & & "host"=& '',& & & & & & "port"=&'',& & & & & & "path"=&'',& & & & & & "query"=&'',& & & & & & "fragment"=&'');& switch (count ($match)) {& & case 10: $parts['fragment'] = $match[9];& & case 9: $parts['query'] = $match[8];& & case 8: $parts['path'] =& $match[7];& & case 7: $parts['path'] =& $match[6] . $parts['path'];& & case 6: $parts['port'] =& $match[5];& & case 5: $parts['host'] =& $match[3]?"[".$match[3]."]":$match[4];& & case 4: $parts['userinfo'] =& $match[2];& & case 3: $parts['scheme'] =& $match[1];& }& $parts['authority'] = ($parts['userinfo']?$parts['userinfo']."@":"").& & & & & & & & & & & && $parts['host'].& & & & & & & & & & & & ($parts['port']?":".$parts['port']:"");& return $parts;}?&When using the url& /* line too long for this site's comment handler */& "foo://username:password@[:42".& & & "/over/there/index.type=animal?name=ferret#nose"The original would returnArray(& & [scheme] =& foo& & [userinfo] =& username:password& & [authority] =& username:password@& & [host] =& & & [port] =& & & [path] =& & & [query] =& & & [fragment] =& )The new one returnsArray(& & [scheme] =& foo& & [userinfo] =& username:password& & [authority] =& username:password@[:42& & [host] =& [:2001::68]& & [port] =& 8042& & [path] =& /over/there/index.type=animal& & [query] =& name=ferret& & [fragment] =& nose)All of the other examples FredLudd used below still work exactly the same.
Here is utf-8 compatible parse_url() replacement function based on "laszlo dot janszky at gmail dot com" work. Original incorrectly handled URLs with user:pass. Also made PHP 5.5 compatible (got rid of now deprecated regex /e modifier).&?php& & function mb_parse_url($url)& & {& & & & $enc_url = preg_replace_callback(& & & & & & '%[^:/@?&=#]+%usD',& & & & & & function ($matches)& & & & & & {& & & & & & & & return urlencode($matches[0]);& & & & & & },& & & & & & $url& & & & );& & & & & & & & $parts = parse_url($enc_url);& & & & & & & & if($parts === false)& & & & {& & & & & & throw new \InvalidArgumentException('Malformed URL: ' . $url);& & & & }& & & & & & & & foreach($parts as $name =& $value)& & & & {& & & & & & $parts[$name] = urldecode($value);& & & & }& & & & & & & & return $parts;& & }?&
&?phpfunction url_parse($url){$sflfdfldf=$url;if(strpos($url,"?")&-1){$a=explode("?",$url,2);$url=$a[0];$query=$a[1];}if(strpos($url,"://")&-1){$scheme=substr($url,0,strpos($url,"//")-1);$url=substr($url,strpos($url,"//")+2,strlen($url));}if(strpos($url,"/")&-1){$a=explode("/",$url,2);$url=$a[0];$path="/".$a[1];}if(strpos($url,":")&-1){$a=explode(":",$url,2);$url=$a[0];$port=$a[1];}$host=$url;$url=null;foreach(array("url","scheme","host","port","path","query") as $var){if(!empty($$var)){$return[$var]=$$var;}}return $return;}?&&?phpprint_r(url_parse(""));print_r(parse_url(""));?&
I was writing unit tests and needed to cause this function to kick out an error and return FALSE in order to test a specific execution path. If anyone else needs to force a failure, the following inputs will work:
&?php
parse_url("");
parse_url("");
parse_url("");
?&
Thanks to xellisx for his parse_query function. I used it in one of my projects and it works well. But it has an error. I fixed the error and improved it a little bit. Here is my version of it:&?phpfunction parse_query($var) {& $var& = parse_url($var, PHP_URL_QUERY);& $var& = html_entity_decode($var);& $var& = explode('&', $var);& $arr& = array();& foreach($var as $val)&& {& & $x& & & & & = explode('=', $val);& & $arr[$x[0]] = $x[1];&& }& unset($val, $x, $var);& return $arr; }?&At the first line there was parse_query($val), I made it $var. It used to return a null array before this fix.I have added the parse_url line. So now the function will only focus in the query part, not the whole URL. This is useful if something like below is done:&?php$my_GET = parse_query($_SERVER['REQUEST_URI']);?&
Created another parse_url utf-8 compatible function.&?phpfunction mb_parse_url($url) {& & $encodedUrl = preg_replace('%[^:/?#&=\.]+%usDe', 'urlencode(\'$0\')', $url);& & $components = parse_url($encodedUrl);& & foreach ($components as &$component)& & & & $component = urldecode($component);& & return $components;}?&
It may be worth reminding that the value of the #fragment never gets sent to the server.& Anchors processing is exclusively client-side.
At least in php 5.6.x this function does appear to work with relative URLs despite what it says above.Obviously it does not return the scheme or host, but it does return the path and query string and fragment from a relative URL.
@ solenoid: Your code was very helpful, but it fails when the current URL has no query string (it appends '&' instead of '?' before the query).& Below is a fixed version that catches this edge case and corrects it.&?phpfunction modify_url($mod) { & & $url = "".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; & & $query = explode("&", $_SERVER['QUERY_STRING']);& & if (!$_SERVER['QUERY_STRING']) {$queryStart = "?";} else {$queryStart = "&";}& & foreach($query as $q) & & { & & & & list($key, $value) = explode("=", $q); & & & & if(array_key_exists($key, $mod)) & & & & { & & & & & & if($mod[$key]) & & & & & & { & & & & & & & & $url = preg_replace('/'.$key.'='.$value.'/', $key.'='.$mod[$key], $url); & & & & & & } & & & & & & else & & & & & & { & & & & & & & & $url = preg_replace('/&?'.$key.'='.$value.'/', '', $url); & & & & & & } & & & & } & & } & & foreach($mod as $key =& $value) & & { & & & & if($value && !preg_match('/'.$key.'=/', $url)) & & & & { & & & & & & $url .= $queryStart.$key.'='.$value; & & & & } & & } & & return $url; } ?&
Here's a good way to using parse_url () gets the youtube link.This function I used in many works:&?phpfunction youtube($url, $width=560, $height=315, $fullscreen=true){& & parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );& & $youtube= '&iframe allowtransparency="true" scrolling="no" width="'.$width.'" height="'.$height.'" src="///embed/'.$my_array_of_vars['v'].'" frameborder="0"'.($fullscreen?' allowfullscreen':NULL).'&&/iframe&';& & return $youtube;}$url=''; youtube($url, 560, 315, true);?&parse_url () allocates a unique youtube code and& put into iframe link and displayed on your page. The size of the videos choose yourself.Enjoy.
Here's a method to get the REAL name of a domain. This return just the domain name, not the rest. First check if is not an IP, then return the name:
&?php
&& function esip($ip_addr)
{
& if(preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$ip_addr))
& {
& & $parts=explode(".",$ip_addr);
& & foreach($parts as $ip_parts)
& & {
& & & if(intval($ip_parts)&255 || intval($ip_parts)&0)
& & & return FALSE; }
& & return TRUE;
& }
& else
& & return FALSE; }
& & function domain($domainb)
& & {
& & $bits = explode('/', $domainb);
& & if ($bits[0]=='http:' || $bits[0]=='https:')
& & {
& & $domainb= $bits[2];
& & } else {
& & $domainb= $bits[0];
& & }
& & unset($bits);
& & $bits = explode('.', $domainb);
& & $idz=count($bits);
& & $idz-=3;
& & if (strlen($bits[($idz+2)])==2) {
& & $url=$bits[$idz].'.'.$bits[($idz+1)].'.'.$bits[($idz+2)];
& & } else if (strlen($bits[($idz+2)])==0) {
& & $url=$bits[($idz)].'.'.$bits[($idz+1)];
& & } else {
& & $url=$bits[($idz+1)].'.'.$bits[($idz+2)];
& & }
& & return $url;
& & }
& &
& & $address='clients1.sub3.google.co.uk';
& & && $parsed_url = parse_url($address);
& & & $check = esip($parsed_url['host']);
& & $host = $parsed_url['host'];
& & if ($check == FALSE){
& & & & if ($host != ""){
& & & & $host = domain($host);
& & & & }else{
& & & & $host = domain($address);& &
& & & & & & }
& & }
& & echo $host;
& & ?&
This return: google.co.uk
'';
return:
'';
return:
Many times& parse_url return nothing when domain
only for example.
Now, , or google.co.uk will return the same.
Maybe is a little dirty, but works well for me, i use it to group internet access log from squid.
Simple static library that allows easy manipulation of url parameters:&?php& & class Url {& & & & public static function explode($sUrl) {& & & & & & $aUrl = parse_url($sUrl);& & & & & & $aUrl['query_params'] = array();& & & & & & $aPairs = explode('&', $aUrl['query']);& & & & & & DU::show($aPairs);& & & & & & foreach($aPairs as $sPair) {& & & & & & & & if (trim($sPair) == '') { }& & & & & & & & list($sKey, $sValue) = explode('=', $sPair);& & & & & & & & $aUrl['query_params'][$sKey] = urldecode($sValue);& & & & & & }& & & & & & return $aUrl;& & & & }& & & & public static function implode($aUrl) {& & & & & & $sQuery = '';& & & & & & & & & & & & if (isset($aUrl['query_params']) && is_array($aUrl['query_params'])) {& & & & & & & & $aPairs = array();& & & & & & & & foreach ($aUrl['query_params'] as $sKey=&$sValue) {& & & & & & & & & & $aPairs[] = $sKey.'='.urlencode($sValue);& & & & & & && & & & & & & & & }& & & & & & & & $sQuery = implode('&', $aPairs);& & & & & & & & } else {& & & & & & & & $sQuery = $aUrl['query'];& & & & & & }& & & & & & & & & & & & $sUrl = & & & & & & & & $aUrl['scheme'] . '://' . (& & & & & & & & & & isset($aUrl['user']) && $aUrl['user'] != '' && isset($aUrl['pass']) & & & & & & & & & & && ? $aUrl['user'] . ':' . $aUrl['pass'] . '@' & & & & & & & & & & && : ''& & & & & & & & ) .& & & & & & & & $aUrl['host'] . (& & & & & & & & & & isset($aUrl['path']) && $aUrl['path'] != ''& & & & & & & & & & && ? $aUrl['path']& & & & & & & & & & && : ''& & & & & & & & ) . (& & & & & & & & && $sQuery != ''& & & & & & & & & & && ? '?' . $sQuery& & & & & & & & & & && : ''& & & & & & & & ) . (& & & & & & & & && isset($aUrl['fragment']) && $aUrl['fragment'] != ''& & & & & & & & & & && ? '#' . $aUrl['fragment']& & & & & & & & & & && : ''& & & & & & & & );& & & & & & return $sUrl;& & & & }& & & & public static function getParams($sUrl) {& & & & & & $aUrl = self::explode($sUrl);& & & & & & return $aUrl['query_params'];& & & & }& & & & public static function setParams($sUrl, $aParams) {& & & & & & $aUrl = self::explode($sUrl);& & & & & & $aUrl['query'] = '';& & & & & & $aUrl['query_params'] = $aParams;& & & & & & return self::implode($aUrl);& & & & }& & & & public static function updateParams($sUrl, $aParams) {& & & & & & $aUrl = self::explode($sUrl);& & & & & & $aUrl['query'] = '';& & & & & & $aUrl['query_params'] = array_merge($aUrl['query_params'], $aParams);& & & & & & return self::implode($aUrl);& & & & }& & }?&
Note that if you pass this function a url without a scheme (www.php.net, as opposed to ), the function will incorrectly parse the results. In my test case it returned the domain under the ['path'] element and nothing in the ['host'] element.
I need to parse out the query string from the referrer, so I created this function.
&?php
function parse_query($val)
{
& $var& = html_entity_decode($var);
& $var& = explode('&', $var);
& $arr& = array();
& foreach($var as $val)
&& {
& & $x& & & & & = explode('=', $val);
& & $arr[$x[0]] = $x[1];
&& }
& unset($val, $x, $var);
& return $arr;
parse_url doesn't works if the protocol doesn't specified. This seems like sandard, even the youtube doesn't gives the protocol name when generates code for embedding which have a look like "///etc".So, to avoid bug, you must always check, whether the provided url has the protocol, and if not (starts with 2 slashes) -- add the "http:" prefix.
To get the params (url query) as Associative array, use this function:
&?php
function convertUrlQuery($query) {
& & $queryParts = explode('&', $query);
& &
& & $params = array();
& & foreach ($queryParts as $param) {
& & & & $item = explode('=', $param);
& & & & $params[$item[0]] = $item[1];
& & }
& &
& & return $params;
}
?&
Hello, for some odd reason, parse_url returns the host (ex. ) as the path when no scheme is provided in the input url. So I've written a quick function to get the real host:
&?php
function getHost($Address) {
&& $parseUrl = parse_url(trim($Address));
&& return trim($parseUrl[host] ? $parseUrl[host] : array_shift(explode('/', $parseUrl[path], 2)));
}
getHost(""); getHost(""); getHost(""); getHost(""); ?&
You could try anything! It gives the host (including the subdomain if exists).
Hope it helped you.
I've been working on a generic class that would make URI parsing / building a little easier.The composer package is here: https://packagist.org/packages/enrise/urihelperAnd the repository is here: /Enrise/UriHelperAn example of the usage:&?php$uri = new \Enrise\Uri('');echo $uri-&getScheme(); echo $uri-&getUser(); echo $uri-&getPass(); echo $uri-&getHost(); echo $uri-&getPort(); echo $uri-&getPath(); echo $uri-&getQuery(); echo $uri-&getFragment(); echo $uri-&isSchemeless(); echo $uri-&isRelative(); $uri-&setScheme('scheme:child:scheme.VALIDscheme123:');$uri-&setPort(null);echo $uri-&getUri(); ?&
UTF-8 aware parse_url() replacement.
I've realized that even though UTF-8 characters are not allowed in URL's, I have to work with a lot of them and parse_url() will break.
Based largely on the work of "mallluhuct at gmail dot com", I added parse_url() compatible "named values" which makes the array values a lot easier to work with (instead of just numbers). I also implemented detection of port, username/password and a back-reference to better detect URL's like this: //
... which, although is technically an invalid URL, it's used extensively on sites like wikipedia in the href of anchor tags where it's valid in browsers (one of the types of URL's you have to support when crawling pages). This will be accurately detected as the host name instead of "path" as in all other examples.
I will submit my complete function (instead of just the RegExp) which is an almost "drop-in" replacement for parse_url(). It returns a cleaned up array (or false) with values compatible with parse_url(). I could have told the preg_match() not to store the unused extra values, but it would complicate the RegExp and make it more difficult to read, understand and extend. The key to detecting UTF-8 characters is the use of the "u" parameter in preg_match().
&?php
function parse_utf8_url($url)
{
& & static $keys = array('scheme'=&0,'user'=&0,'pass'=&0,'host'=&0,'port'=&0,'path'=&0,'query'=&0,'fragment'=&0);
& & if (is_string($url) && preg_match(
& & & & & & '~^((?P&scheme&[^:/?#]+):(//))?((\\3|//)?(?:(?P&user&[^:]+):(?P&pass&[^@]+)@)?(?P&host&[^/?:#]*))(:(?P&port&\\d+))?' .
& & & & & & '(?P&path&[^?#]*)(\\?(?P&query&[^#]*))?(#(?P&fragment&.*))?~u', $url, $matches))
& & {
& & & & foreach ($matches as $key =& $value)
& & & & & & if (!isset($keys[$key]) || empty($value))
& & & & & & & & unset($matches[$key]);
& & & & return $matches;
& & }
& & return false;
}
?&
UTF-8 URL's can/should be "normalized" after extraction with this function.
Modification to the code from:theoriginalmarksimpson at gmail dot comChange:$r .= "(?:(?P&login&\w+):(?P&pass&\w+)@)?";Replace with:$r .= "(?:(?P&login&\w+):?(?P&pass&\w+)?@)?";This will cover the case the only username is present in the url:
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 { if (isset($urlInfo['scheme']) ) {
& & & & & & switch( $urlInfo['scheme'] ) {
& & & & & & & & case 'http':
& & & & & & & & & & $port = 80;
& & & & & & & & case 'https':
& & & & & & & & & & $port = 443;
& & & & & & & & case 'ftp':
& & & & & & & & & & $port = 21;
& & & & & & & & case 'ftps':
& & & & & & & & & & $port = 990;
& & & & & & & & default:
& & & & & & & & & & $port = 0;
& & & & & & }
& & & & } else {
& & & & & & $port = 0; }
& & }
& & return $port;
}
$url = "";
$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;
}
?&
URL's in the query string of a relative URL will cause a problemfails:/page.php?foo=bar&url=parses:
Noticed the following differences in error handling:&?php & & print_r(parse_url(''));?&In PHP 5.2.6 returns:Array(& & [scheme] =& ftp& & [host] =& host& & [user] =& user& & [pass] =& password)port is just skipped.But in PHP 5.3.6 returns NULL without any warnings.
my function catch the url written on the browser by the user and does the same thing of parse_url. but better, I think. I don't like parse_url because it says nothing about elements that it doesn't find in the url. my function instead return an empty string.&?phpfunction get_url(){& & $arr = array();& & $uri = $_SERVER['REQUEST_URI'];& & $x = array_pad( explode( '?', $uri ), 2, false );& & $arr['query'] = ( $x[1] )? $x[1] : '' ;& & $x& & & && = array_pad( explode( '/', $x[0] ), 2, false );& & $x_last = array_pop( $x );& & if( strpos( $x_last, '.' ) === false )& & {& & & & $arr['resource'] = '';& & & & $x[] = $x_last;& & }& & else& & {& & & & $arr['resource'] = $x_last;& & }& & $arr['path'] = implode( '/', $x );& & if( substr( $arr['path'], -1 ) !== '/' ) $arr['path'] .= '/';& & $arr['domain']& & = $_SERVER['SERVER_NAME'];& & $server_prt& & & & = explode( '/', $_SERVER['SERVER_PROTOCOL'] );& & $arr['scheme']& & = strtolower( $server_prt[0] );& & $arr['url'] = $arr['scheme'].'://'.$arr['domain'].$uri;& & return $arr;}?&PS: I found working with explode is faster than using preg_match (I tryed with getmicrotime function and 'for' cycles).PPS: I used array_pad to prevent any notice.
Based on the idea of "jbr at ya-right dot com" have I been working on a new function to parse the url:&?phpfunction parseUrl($url) {& & $r& = "^(?:(?P&scheme&\w+)://)?";& & $r .= "(?:(?P&login&\w+):(?P&pass&\w+)@)?";& & $r .= "(?P&host&(?:(?P&subdomain&[\w\.]+)\.)?" . "(?P&domain&\w+\.(?P&extension&\w+)))";& & $r .= "(?::(?P&port&\d+))?";& & $r .= "(?P&path&[\w/]*/(?P&file&\w+(?:\.\w+)?)?)?";& & $r .= "(?:\?(?P&arg&[\w=&]+))?";& & $r .= "(?:#(?P&anchor&\w+))?";& & $r = "!$r!";& & & & & & & & & & & & & & & & & & & & & & & & preg_match ( $r, $url, $out );& & & & return $out;}print_r ( parseUrl ( 'me:you@sub.site.org:29000/pear/validate.html?happy=me&sad=you#url' ) );?&This returns:Array(& & [0] =& me:you@sub.site.org:29000/pear/validate.html?happy=me&sad=you#url& & [scheme] =& & & [1] =& & & [login] =& me& & [2] =& me& & [pass] =& you& & [3] =& you& & [host] =& sub.site.org& & [4] =& sub.site.org& & [subdomain] =& sub& & [5] =& sub& & [domain] =& site.org& & [6] =& site.org& & [extension] =& org& & [7] =& org& & [port] =& 29000& & [8] =& 29000& & [path] =& /pear/validate.html& & [9] =& /pear/validate.html& & [file] =& validate.html& & [10] =& validate.html& & [arg] =& happy=me&sad=you& & [11] =& happy=me&sad=you& & [anchor] =& url& & [12] =& url)So both named and numbered array keys are possible.It's quite advanced, but I think it works in any case... Let me know if it doesn't...
Hi,if you have problems with UTF8 encoded urls please see
. parse_url breaks the utf8. :( You have to implement it yourself.
This function never works the way you think it should...Example....&?phpprint_r ( parse_url ( 'me:you@sub.site.org/pear/validate.html?happy=me&sad=you#url' ) );?&Returns...Array(& & [scheme] =& me& & [path] =& you@sub.site.org/pear/validate.html& & [query] =& happy=me&sad=you& & [fragment] =& url)Here my way of doing parse_url&?phpfunction parseUrl ( $url ){& & $r& = '!(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?';& & $r .= '(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))?!i';& & preg_match ( $r, $url, $out );& & return $out;}print_r ( parseUrl ( 'me:you@sub.site.org/pear/validate.html?happy=me&sad=you#url' ) );?&Returns...Array(& & [0] =& me:you@sub.site.org/pear/validate.html?happy=me&sad=you#url& & [1] =& & & [2] =& me& & [3] =& you& & [4] =& sub.site.org& & [5] =& & & [6] =& /pear/validate.html& & [7] =& happy=me&sad=you& & [8] =& url)Where as...out[0] = full urlout[1] = scheme or '' if no scheme was foundout[2] = username or '' if no auth username was foundout[3] = password or '' if no auth password was foundout[4] = domain name or '' if no domain name was foundout[5] = port number or '' if no port number was foundout[6] = path or '' if no path was foundout[7] = query or '' if no query was foundout[8] = fragment or '' if no fragment was found
Note that older versions of PHP (e.g., 4.1) returned an blank string as the path for URLs without any path, such as However more recent versions of PHP (e.g., 4.4.7) don't set the path element in the array, so old code will get a PHP warning about an undefined index.
an update to the glue url function.you are able to put a host and a path without a slash at the beginning of the path&?phpfunction glue_url($parsed) & & {& & if (! is_array($parsed)) return false;& & $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '':'//'): '';& & $uri .= isset($parsed['user']) ? $parsed['user'].($parsed['pass']? ':'.$parsed['pass']:'').'@':'';& & $uri .= isset($parsed['host']) ? $parsed['host'] : '';& & $uri .= isset($parsed['port']) ? ':'.$parsed['port'] : '';& & if(isset($parsed['path']))& & & & {& & & & $uri .= (substr($parsed['path'],0,1) == '/')?$parsed['path']:'/'.$parsed['path'];& & & & }& & $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : '';& & $uri .= isset($parsed['fragment']) ? '#'.$parsed['fragment'] : '';& & return $uri;& & }?&
Here's a function which implements resolving a relative URL according to RFC 2396 section 5.2. No doubt there are more efficient implementations, but this one tries to remain close to the standard for clarity. It relies on a function called "unparse_url" to implement section 7, left as an exercise for the reader (or you can substitute the "glue_url" function posted earlier).&?phpfunction resolve_url($base, $url) {& & & & if (!strlen($base)) return $url;& & & & if (!strlen($url)) return $base;& & & & if (preg_match('!^[a-z]+:!i', $url)) return $url;& & & & $base = parse_url($base);& & & & if ($url{0} == "#") {& & & & & & & & $base['fragment'] = substr($url, 1);& & & & & & & & return unparse_url($base);& & & & }& & & & unset($base['fragment']);& & & & unset($base['query']);& & & & if (substr($url, 0, 2) == "//") {& & & & & & & & return unparse_url(array(& & & & & & & & & & & & 'scheme'=&$base['scheme'],& & & & & & & & & & & & 'path'=&$url,& & & & & & & & ));& & & & } else if ($url{0} == "/") {& & & & & & & & $base['path'] = $url;& & & & } else {& & & & & & & & $path = explode('/', $base['path']);& & & & & & & & $url_path = explode('/', $url);& & & & & & & & array_pop($path);& & & & & & & & $end = array_pop($url_path);& & & & & & & & foreach ($url_path as $segment) {& & & & & & & & & & & & if ($segment == '.') {& & & & & & & & & & & & & & & & } else if ($segment == '..' && $path && $path[sizeof($path)-1] != '..') {& & & & & & & & & & & & & & & & array_pop($path);& & & & & & & & & & & & } else {& & & & & & & & & & & & & & & & $path[] = $segment;& & & & & & & & & & & & }& & & & & & & & }& & & & & & & & if ($end == '.') {& & & & & & & & & & & & $path[] = '';& & & & & & & & } else if ($end == '..' && $path && $path[sizeof($path)-1] != '..') {& & & & & & & & & & & & $path[sizeof($path)-1] = '';& & & & & & & & } else {& & & & & & & & & & & & $path[] = $end;& & & & & & & & }& & & & & & & & $base['path'] = join('/', $path);& & & & }& & & & return unparse_url($base);}?&
Heres a simple function to add the $component option in for PHP4. Haven't done exhaustive testing, but should work ok.&?php& & if(!defined('PHP_URL_SCHEME')) define('PHP_URL_SCHEME', 1);& & if(!defined('PHP_URL_HOST')) define('PHP_URL_HOST', 2);& & if(!defined('PHP_URL_PORT')) define('PHP_URL_PORT', 3);& & if(!defined('PHP_URL_USER')) define('PHP_URL_USER', 4);& & if(!defined('PHP_URL_PASS')) define('PHP_URL_PASS', 5);& & if(!defined('PHP_URL_PATH')) define('PHP_URL_PATH', 6);& & if(!defined('PHP_URL_QUERY')) define('PHP_URL_QUERY', 7);& & & & & & & & & & & & & & if(!defined('PHP_URL_FRAGMENT')) define('PHP_URL_FRAGMENT', 8);& & & & & & function parse_url_compat($url, $component=NULL){& & & & & & & & if(!$component) return parse_url($url);& & & & & & & & if(phpversion() &= 5)& & & & & & return parse_url($url, $component);& & & & $bits = parse_url($url);& & & & & & & & switch($component){& & & & & & case PHP_URL_SCHEME: return $bits['scheme'];& & & & & & case PHP_URL_HOST: return $bits['host'];& & & & & & case PHP_URL_PORT: return $bits['port'];& & & & & & case PHP_URL_USER: return $bits['user'];& & & & & & case PHP_URL_PASS: return $bits['pass'];& & & & & & case PHP_URL_PATH: return $bits['path'];& & & & & & case PHP_URL_QUERY: return $bits['query'];& & & & & & case PHP_URL_FRAGMENT: return $bits['fragment'];& & & & }& & & & & & }?&
What about using something like this to safely encoding all the values that are passed in the query portion?Example input:Result:&?phpfunction safe_url($url) {& if(!empty($url)) {& & $urllist=parse_url($url);& & if(is_array($urllist) && isset($urllist["query"])) {& & & $keyvalue_list=explode("&",($urllist["query"]));& & & $keyvalue_result=array();& & & foreach($keyvalue_list as $key=&$value) {& & & & $keyvalue=explode("=",$value);& & & & if(count($keyvalue)==2) {& & & & & $keyvalue[1]=urlencode($keyvalue[1]);& & & & & array_push($keyvalue_result,implode("=",$keyvalue));& & & & }& & & }& & & $urllist["query"]=implode("&",$keyvalue_result);& & & $url=(isset($urllist["scheme"])?$urllist["scheme"]."://":"").& & & & && (isset($urllist["user"])?$urllist["user"].":":"").& & & & && (isset($urllist["pass"])?$urllist["pass"]."@":"").& & & & && (isset($urllist["host"])?$urllist["host"]:"").& & & & && (isset($urllist["port"])?":".$urllist["port"]:"").& & & & && (isset($urllist["path"])?$urllist["path"]:"").& & & & && (isset($urllist["query"])?"?".$urllist["query"]:"").& & & & && (isset($urllist["fragment"])?"#".$urllist["fragment"]:"");& & }& }& & return $url;}?&
Please note that parse_url seems not to produce always the same results when passing non-standard urls.Eg. I was using this code since 2005 (both under PHP 4.3.10 and PHP 5.2.3) :&?php& $p = parse_url ( '' ) ;& $d2 = parse_url ( $p['path'] ) ;& echo $d2 ;& ?&Of course my example is very specific, as URL is not really correct. But using parse_url was a great trick to split URL easily (without using regular expressions).Unfortunately under PHP 5.2.0-8 (+etch10), parse_url will fail as it does not accept the slash (/) at the beginning of URL.Here is a possible patch :&?php& $p = parse_url ( '' ) ;& $d2 = parse_url ( substr ( $p['path'] , 1 ) ) ;& echo $d2 ;& ?&However this last code is not optimized at all, and should be replaced by a regular expression to split URL (so that parse_url would be no longer used).So you should use parse_url very carefully, and verify that you pass only standard URLs...
You may want to check out the PEAR NET_URL class. It provides easy means to manipulate URL strings.
Do not look for the fragment in $_SERVER['QUERY_STRING'], you will not find it. You should read the fragment in JavaScript for example.
Here's the easiest way to get the URL to the path that your script is in (so not the actual script name itself, just the complete URL to the folder it's in)echo "".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
based on the "laulibrius at hotmail dot com" function, this work for relatives url only:&?phpfunction parseUrl($url) {$r = "^(?:(?P&path&[\.\w/]*/)?";$r .= "(?P&file&\w+(?:\.\w+)?)?)\.(?P&extension&\w+)?";$r .= "(?:\?(?P&arg&[\w=&]+))?";$r .= "(?:#(?P&anchor&\w+))?";$r = "!$r!";preg_match ( $r, $url, $out );return $out;}print_r(parseUrl("../test/f.aq.php?p=1&v=blabla#X1"));?&returns:Array(& & [0] =& ../test/faq.php?p=1&v=blabla#X1& & [path] =& ../test/& & [1] =& ../test/& & [file] =& faq& & [2] =& faq& & [extension] =& php& & [3] =& php& & [arg] =& p=1&v=blabla& & [4] =& p=1&v=blabla& & [anchor] =& X1& & [5] =& X1)
There was one thing missing in the function dropped by "to1ne at hotmail dot com" when i tried it : domain and subdomain couldn't have a dash "-". So i add it in the regexp and the function looks like this now :&?php& & function parseUrl($url) {& & & & $r& = "^(?:(?P&scheme&\w+)://)?";& & & & $r .= "(?:(?P&login&\w+):(?P&pass&\w+)@)?";& & & & $r .= "(?P&host&(?:(?P&subdomain&[-\w\.]+)\.)?" . "(?P&domain&[-\w]+\.(?P&extension&\w+)))";& & & & $r .= "(?::(?P&port&\d+))?";& & & & $r .= "(?P&path&[\w/]*/(?P&file&\w+(?:\.\w+)?)?)?";& & & & $r .= "(?:\?(?P&arg&[\w=&]+))?";& & & & $r .= "(?:#(?P&anchor&\w+))?";& & & & $r = "!$r!";& & & & & & & & & & & & & & & & & & & & & & & & preg_match ( $r, $url, $out );& & && & & & & return $out;& & }?&Btw, thanks for the function, it helps me a lot.
It seems the host-part strips off the last [:port] off the end of the hostname
When something is wrong in the actual request, this proves to be the wrong way to do things.
It would be better to not strip off the [:port], but to keep the string *before* the first [:port] as the hostname.
Problem with (maybe malformed) provided HTTP_HOST
hostname:443:443
that resolved in
'host' =& 'hostname:443'
Which gave me problems.
Solution would be to enforce this yourself, explicitly:
&?php
$p = parse_url( $url );
$host = explode(':', $p['host']);
$hostname = $host[0];
?&
Another update to the glue_url function: applied the "isset" treatment to $parsed['pass'].&?phpfunction glue_url($parsed){& & if (!is_array($parsed)) return false;& & $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : '';& & $uri .= isset($parsed['user']) ? $parsed['user'].(isset($parsed['pass']) ? ':'.$parsed['pass'] : '').'@' : '';& & $uri .= isset($parsed['host']) ? $parsed['host'] : '';& & $uri .= isset($parsed['port']) ? ':'.$parsed['port'] : '';& & if(isset($parsed['path']))& & {& & & & $uri .= (substr($parsed['path'], 0, 1) == '/') ? $parsed['path'] : ('/'.$parsed['path']);& & }& & $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : '';& & $uri .= isset($parsed['fragment']) ? '#'.$parsed['fragment'] : '';& & return $uri;}?&
I searched for an implementation of rfc3986, which is a newer version of rfc 2392. I may find it here : & - read the rfc at &
Another shot at trying to find a better parser. I noticed that the laulibrius/theoriginalmarksimpson functions didn't quite handle the URL for the page they were displayed on. For my mirror, ca3, this is& Run it through the function and it parses to& scheme =& http& login =&& pass =&& host =& ca3.php.net& ip =&& subdomain =& ca3& domain =& php.& extension =& net& port =&& path =& /manual/en/function.parse& file =& function.parsethat is, the file name gets a bit mangledRather than tweak the function's regular expression yet again, I opted to adapt a RegExp that served me well in Javascript:function j_parseUrl($url) {& $r& = "(?:([a-z0-9+-._]+)://)?";& $r .= "(?:";& $r .=&& "(?:((?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9a-f]{2})*)@)?";& $r .=&& "((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9a-f]{2})*)";& $r .=&& "(?::(\d*))?";& $r .=&& "(/(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9a-f]{2})*)?";& $r .=&& "|";& $r .=&& "(/?";& $r .=& && "(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+";& $r .=& && "(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9a-f]{2})*";& $r .=& & ")?";& $r .= ")";& $r .= "(?:\?((?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9a-f]{2})*))?";& $r .= "(?:#((?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9a-f]{2})*))?";& preg_match("`$r`i", $url, $match);& $parts = array(& & & & & & "scheme"=&'',& & & & & & "userinfo"=&'',& & & & & & "authority"=&'',& & & & & & "host"=& '',& & & & & & "port"=&'',& & & & & & "path"=&'',& & & & & & "query"=&'',& & & & & & "fragment"=&'');& switch (count ($match)) {& & case 9: $parts['fragment'] = $match[8];& & case 8: $parts['query'] = $match[7];& & case 7: $parts['path'] =& $match[6];& & case 6: $parts['path'] =& $match[5] . $parts['path'];& & case 5: $parts['port'] =& $match[4];& & case 4: $parts['host'] =& $match[3];& & case 3: $parts['userinfo'] =& $match[2];& & case 2: $parts['scheme'] =& $match[1];& }& $parts['authority'] = ($parts['userinfo']?$parts['userinfo']."@":"").& & & & & & & & & & & && $parts['host'].& & & & & & & & & & & & ($parts['port']?":".$parts['port']:"");& return $}This function, when fed "", returns& scheme =& http& userinfo =&& authority =& ca3.php.net& host =& ca3.php.net& port =&& path =& /manual/en/function.parse-url.php& query =&& fragment =& which is somewhat closer to my needs.But everything should be tested against the two examples provided by RFC3986,& /* line too long for this site's commnet handler */& "foo://username::8042".& & & "/over/there/index.type=animal?name=ferret#nose"and& "urn:example:animal:ferret:nose"Here the native function parse_url() performs admirably on that "urn:" example. Mine fails to pick out the path ("example:animal:ferret:nose") and the laulibrius/theoriginalmarksimpson function can't decipher anything there. On the "foo:" example, both my function and parse_url() get it right, while the other examples on this page don't.The laulibrius/theoriginalmarksimpson function delivers& scheme =& foo& login =& username& pass =& password& host =& & ip =&& subdomain =&& domain =& example.& extension =& com& port =& 8042& path =& /over/there/index.dtb& file =& index.dtbAs you can see, the query string ("name=ferret") and fragment ("nose") have dropped off, as well as the parameter ("type=animal").
Here is an update to the glue_url() function.
It can now handle relative URLs if only 'path' is provided.
&?php
function glue_url($parsed) {
& & if (!is_array($parsed)) {
& & & & return false;
& & }
& & $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : '';
& & $uri .= isset($parsed['user']) ? $parsed['user'].(isset($parsed['pass']) ? ':'.$parsed['pass'] : '').'@' : '';
& & $uri .= isset($parsed['host']) ? $parsed['host'] : '';
& & $uri .= isset($parsed['port']) ? ':'.$parsed['port'] : '';
& & if (isset($parsed['path'])) {
& & & & $uri .= (substr($parsed['path'], 0, 1) == '/') ?
& & & & & & $parsed['path'] : ((!empty($uri) ? '/' : '' ) . $parsed['path']);
& & }
& & $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : '';
& & $uri .= isset($parsed['fragment']) ? '#'.$parsed['fragment'] : '';
& & return $uri;
}
?&
For those of you sending URLs in HTML emails with a redirect address in the query string, note that Hotmail unescapes / and : characters in the query string. So that breaks the parse_url() function call. Take this as an example:href=""Hotmail will transform it to this:href=""The solution is to be preventive before the call to parse_url():&?php$q_index = strpos($uri, '?');if ($q_index !== FALSE && & (strpos($uri, ':', $q_index) !== FALSE || strpos($uri, '/', $q_index) !== FALSE)) {& $begin = substr($uri, 0, $q_index);& $end = substr($uri, $q_index, strlen($uri)-$q_index);& $end = str_replace('/', '%2F', $end);& $end = str_replace(':', '%3A', $end);& $uri = $begin.$end;}?&
A simple function using "parse_url" to find the base URL of the given link.&?phpfunction getPrimaryDomain($url) {& $tld = parse_url($url,PHP_URL_HOST);& $tldArray = explode(".",$tld);& & $l1 = '0';& & foreach($tldArray as $s) {& & if($s == 'com' || $s == 'net' || $s == 'info' || $s == 'biz' || $s == 'us' || $s == 'co' || $s == 'org' || $s == 'me') {& & & & & & $l2 = $l1 - 1;& & & & }& & else {& & & $l1++;& & }& }& & echo $tldArray[$l2] . '.' . $tldArray[$l1];}getPrimaryDomain(');?&
Here's a piece of code that modifies, replaces or removes the url query. This can typically used in paging situations where there are more parameters than the page.
&?php
function modify_url($mod)
{
& & $url = "".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
& & $query = explode("&", $_SERVER['QUERY_STRING']);
& & foreach($query as $q)
& & {
& & & & list($key, $value) = explode("=", $q);
& & & & if(array_key_exists($key, $mod))
& & & & {
& & & & & & if($mod[$key])
& & & & & & {
& & & & & & & & $url = preg_replace('/'.$key.'='.$value.'/', $key.'='.$mod[$key], $url);
& & & & & & }
& & & & & & else
& & & & & & {
& & & & & & & & $url = preg_replace('/&?'.$key.'='.$value.'/', '', $url);
& & & & & & }
& & & & }
& & }
& & foreach($mod as $key =& $value)
& & {
& & & & if($value && !preg_match('/'.$key.'=/', $url))
& & & & {
& & & & & & $url .= '&'.$key.'='.$value;
& & & & }
& & }
& & return $url;
}
$url = modify_url(array('p' =& 4, 'show' =& 'column'));
In reply to adrian,Thank you very much for your function. There is a small issue with your relative protocol function. You need to remove the // when making the url the path. Here is the new function.function resolve_url($base, $url) {& & & & if (!strlen($base)) return $& & & & // Step 2& & & & if (!strlen($url)) return $& & & & // Step 3& & & & if (preg_match('!^[a-z]+:!i', $url)) return $& & & & $base = parse_url($base);& & & & if ($url{0} == "#") {& & & & & & & & // Step 2 (fragment)& & & & & & & & $base['fragment'] = substr($url, 1);& & & & & & & & return unparse_url($base);& & & & }& & & & unset($base['fragment']);& & & & unset($base['query']);& & & & if (substr($url, 0, 2) == "//") {& & & & & & & & // Step 4& & & & & & & & return unparse_url(array(& & & & & & & & & & & & 'scheme'=&$base['scheme'],& & & & & & & & & & & & 'path'=&substr($url,2),& & & & & & & & ));& & & & } else if ($url{0} == "/") {& & & & & & & & // Step 5& & & & & & & & $base['path'] = $& & & & } else {& & & & & & & & // Step 6& & & & & & & & $path = explode('/', $base['path']);& & & & & & & & $url_path = explode('/', $url);& & & & & & & & // Step 6a: drop file from base& & & & & & & & array_pop($path);& & & & & & & & // Step 6b, 6c, 6e: append url while removing "." and ".." from& & & & & & & & // the directory portion& & & & & & & & $end = array_pop($url_path);& & & & & & & & foreach ($url_path as $segment) {& & & & & & & & & & & & if ($segment == '.') {& & & & & & & & & & & & & & & & // skip& & & & & & & & & & & & } else if ($segment == '..' && $path && $path[sizeof($path)-1] != '..') {& & & & & & & & & & & & & & & & array_pop($path);& & & & & & & & & & & & } else {& & & & & & & & & & & & & & & & $path[] = $& & & & & & & & & & & & }& & & & & & & & }& & & & & & & & // Step 6d, 6f: remove "." and ".." from file portion& & & & & & & & if ($end == '.') {& & & & & & & & & & & & $path[] = '';& & & & & & & & } else if ($end == '..' && $path && $path[sizeof($path)-1] != '..') {& & & & & & & & & & & & $path[sizeof($path)-1] = '';& & & & & & & & } else {& & & & & & & & & & & & $path[] = $& & & & & & & & }& & & & & & & & // Step 6h& & & & & & & & $base['path'] = join('/', $path);& & & & }& & & & // Step 7& & & & return unparse_url($base);}
If you want to get host, function will return NULL if you pass only host.Example:&?phpparse_url($url, PHP_URL_HOST);?&$url =& value returned =& string '' (length=11) =&string '' (length=15) =& string '' (length=15) =& null =& null:8080 =& string '' (length=11):8080 =& string '' (length=15)}

我要回帖

更多关于 not at all是什么意思 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信