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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: leif at flattr dot com
New email:
PHP Version: OS:

 

 [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: Sun Jul 13 23:01:33 2025 UTC