PHP 8.5.0 Released!

Voting

: max(four, nine)?
(Example: nine)

The Note You're Voting On

to1ne at hotmail dot com
17 years ago
Based on the idea of "jbr at ya-right dot com" have I been working on a new function to parse the url:
<?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!"; // Delimiters
 
 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...

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /