|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33333 strpos (and other functions) not seeing a character that is very clearly there
Submitted: 2005-06-14 07:50 UTC Modified: 2005-06-15 07:38 UTC
From: FxChiP at Gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.11 OS: *nix most likely
Private report: No CVE-ID: None
 [2005-06-14 07:50 UTC] FxChiP at Gmail dot com
Using explode(), strpos(), and probably any other string-related function in conjunction with a string returned from fgets() will (at least sometimes) produce an incorrect result. 

i.e. if there is a line like this in a file called public_covers.db:

FxChiP?this is a test statement?guitar?

The *entire string* will be the first element in the array created by explode(). More information is included in the reproduce code. 

Contents of the public_covers.db file:

FxChiP?this is a test statement?guitar?
duality515?Vermilion Pt2?bass?jimroot54_vermilionpt2.mp3?pwnage?1113877848?1113967262
duality515?Everything Ends?guitar?macca_everythingends.mp3?w00t?1113967262?1113967262

Reproduce code:
	$public_db = fopen("public_covers.db", "r");
	$bwerp = explode('?', fgets($public_db));

Expected result:
From the var_dump, I'd expect to see an array consisting of everything "in between" the ? characters.

Actual result:
array(1) { [0]=>  string(84) "FxChiP?this is a test statement?guitar? " }


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-14 08:45 UTC]
Nice bug #

For reports like this, you really need to provide the od -c or od -x output of both the relevant bits of the script file and the input file.  I think you will find that what is in the file and what is in the script are two different things that whatever you are using to view both just happen to look similar.  Just because two things look similar does not mean that it is the same byte sequence behind them.
 [2005-06-15 07:28 UTC] FxChiP at Gmail dot com

My error. As it turns out, using GNOME's gedit (aka "Text Editor" under Accessories) on the offending PHP scripts is what actually caused the problem.

It caused a  character to be prepended before the § which is what probably caused the error. I fixed this by opening the test-script in an editor that doesn't put strange characters in. ;) (eVim/gVim to be exact, but emacs should work too, I'm not trying to start a flamewar if that's even possible on a bug tracker)

My apologies for not trying everything and filing a bug before it was absolutely necessary, which took up valuable hard drive space on your servers. I'll try to be more careful next time :)
 [2005-06-15 07:38 UTC]
Not a bug then
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 09:01:27 2024 UTC