#33333 [Fbk->Opn]: strpos (and other functions) not seeing a character that is very clearly there

From: Date: Wed, 15 Jun 2005 05:28:43 +0000
Subject: #33333 [Fbk->Opn]: strpos (and other functions) not seeing a character that is very clearly there
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-80351@lists.php.net to get a copy of this message
ID: 33333 User updated by: FxChiP at Gmail dot com Reported By: FxChiP at Gmail dot com -Status: Feedback +Status: Open Bug Type: Strings related Operating System: *nix most likely PHP Version: 4.3.11 New Comment: ... 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 :) Previous Comments: ------------------------------------------------------------------------ [2005-06-14 08:45:20] rasmus@php.net 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-14 07:50:01] FxChiP at Gmail dot com Description: ------------ 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§akczf.pk.gif§whee§1113865622§1113967262 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§akczf.pk.gif§whee§1113865622§1113967262 duality515§Vermilion Pt2§bass§jimroot54_vermilionpt2.mp3§pwnage§1113877848§1113967262 duality515§Everything Ends§guitar§macca_everythingends.mp3§w00t§1113967262§1113967262 duality515§gsg§bass§temp.jpg§§1116469075§1113967262 Reproduce code: --------------- <?PHP $public_db = fopen("public_covers.db", "r"); $bwerp = explode('§', fgets($public_db)); var_dump($bwerp); ?> 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§akczf.pk.gif§whee§1113865622§1113967262 " } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33333&edit=1

« previous php.bugs (#80351) next »