note 83998 deleted from function.parse-url by cmb
| From: | cmb@php.net | Date: | Sun, 16 Jun 2019 08:24:42 +0000 |
| Subject: | note 83998 deleted from function.parse-url by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211285@lists.php.net to get a copy of this message | ||
Note Submitter: Cool Coyote
----
based on the "laulibrius at hotmail dot com" function, this work for relatives url only:
<?php
function 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
)