php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18127 explode not exploding
Submitted: 2002-07-03 02:31 UTC Modified: 2002-07-03 03:30 UTC
From: BlackMagic at computer dot org Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.1.2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: BlackMagic at computer dot org
New email:
PHP Version: OS:

 

 [2002-07-03 02:31 UTC] BlackMagic at computer dot org
I'm using explode() to parse a street address from a web form looking for 0x0D characters, eg, $x = explode(0x0D, $address); 

The entire address ends up in $x, no matter how many line feeds it contains. 

The same thing happens with this code:
$linefeed = 0x0D;
$x = explode($linefeed, $address); 

This works, returning the correct value in $lines:
$y = $lines = 0; 
$x = 1;
while ($x) {                                
  $x = strpos($address, 0x0D, $y);  
  $y = $x + 1;
  $lines++; }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-03 02:50 UTC] derick@php.net
From the manual:
explode -- Split a string by string
Description
array explode ( string separator, string string [, int limit])

Your separator is 0x0D which is 13. Becuase 13 is not a 'string' it will be converted to the string "13" and aas there is no "13" in your string, it won't be exploded.

User the following line instead:
explode ("\n", $address);

Derick
 [2002-07-03 03:23 UTC] BlackMagic at computer dot org
Derick,

Thank you for the prompt response, and a fix that works.

Without wanting to draw the matter out, there is an inconsistency in the way explode() works vis-a-vis strpos(). 

The manual entry for strpos() also says the item being searched for must be a string, but $x = strpos($address, 0x0D, $y); works fine.
 [2002-07-03 03:30 UTC] derick@php.net
The strpos manual page says:

"If needle is not a string, it is converted to an integer and applied as the ordinal value of a character."

and as 0x0D is clearly not a string, but a number it is applied as the ordinal number here.

(Please leave the status as bogus, this is the state for non-bugs).

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 09:01:27 2024 UTC