note 81822 deleted from function.parse-url by cmb
| From: | cmb@php.net | Date: | Sun, 06 Oct 2019 08:15:36 +0000 |
| Subject: | note 81822 deleted from function.parse-url by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212502@lists.php.net to get a copy of this message | ||
Note Submitter: Nicolas Merlet - admin(at)merletn.org
----
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 ( 'http://domain.tld/tcp://domain2.tld/dir/file'
) ;
$d2 = parse_url ( $p['path'] ) ;
echo $d2 ; // returns '/dir/file'
?>
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 ( 'http://domain.tld/tcp://domain2.tld/dir/file'
) ;
$d2 = parse_url ( substr ( $p['path'] , 1 ) ) ;
echo $d2 ; // returns '/dir/file'
?>
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...