php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41834 pathinfo() parse a path like "/opt/" in wrong result
Submitted: 2007-06-28 07:32 UTC Modified: 2007-07-11 07:52 UTC
From: donyad at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.3 OS: Window2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
45 + 34 = ?
Subscribe to this entry?

 
 [2007-06-28 07:32 UTC] donyad at gmail dot com
Description:
------------
Use pathinfo() or basename() to parse a string "/opt/"
it will tell me the path is "\" and the filename is "opt"


Reproduce code:
---------------
<?php

parsePath("/opt/");
parsePath("/opt/file");

function parsePath($str) {
  print("dirname:" . dirname($str) . "<br />\n");
  print("basename:" . basename($str) . "<br />\n");

  print("pathinfo:");
  print_r(pathinfo($str));
  print("<br /><br />\n");
}

?>

Expected result:
----------------
dirname:/opt
basename:
pathinfo:Array ( [dirname] => /opt [basename] => [filename] => )

dirname:/opt
basename:file
pathinfo:Array ( [dirname] => /opt [basename] => file [filename] => file ) 

even return the "/" as "\" is acceptable

dirname:\opt
basename:
pathinfo:Array ( [dirname] => \opt [basename] => [filename] => )

dirname:/opt
basename:file
pathinfo:Array ( [dirname] => /opt [basename] => file [filename] => file ) 

Actual result:
--------------
dirname:\
basename:opt
pathinfo:Array ( [dirname] => \ [basename] => opt [filename] => opt )

dirname:/opt
basename:file
pathinfo:Array ( [dirname] => /opt [basename] => file [filename] => file ) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-28 08:17 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That's because "/opt/" is not a valid path on Win32.
 [2007-06-28 09:21 UTC] donyad at gmail dot com
Actually, I am parsing URL such like "www.php.net/manual/", "/opt/" just an example

Even parse string "/opt/" under my Debian4.0-apache2-PHP5.2.0, this example code return the same result to me.
 [2007-07-11 07:52 UTC] jani@php.net
pathinfo() is a filesystem function, not URL function.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC