php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52803 parse_url can't handle urls without a scheme.
Submitted: 2010-09-09 18:02 UTC Modified: 2010-09-09 18:08 UTC
From: leif at flattr dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.3 OS: osx and debian linux
Private report: No CVE-ID: None
 [2010-09-09 18:02 UTC] leif at flattr dot com
Description:
------------
parse_url will falsely use the hostname as path if url doesn't include the scheme part.




Test script:
---------------
php > echo var_dump(parse_url('hejhopp.com/'));


Expected result:
----------------
array(1) {
  ["host"]=>
  string(11) "hejhopp.com"
  ["path"]=>
  string(1) "/"
}

Actual result:
--------------
array(1) {
  ["path"]=>
  string(12) "hejhopp.com/"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-09 18:05 UTC] scottmac@php.net
-Status: Open +Status: Bogus
 [2010-09-09 18:05 UTC] scottmac@php.net
The function is designed to work with a fully qualified URL, does the manual 
suggest otherwise?
 [2010-09-09 18:08 UTC] leif at flattr dot com
Yes the manual suggests otherwise.

"Partial URLs are also accepted, parse_url() tries its best to parse them correctly." - php manual

I would expect parse_url to try to parse from left to right starting with scheme and then moving on to host.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 05:01:34 2025 UTC