php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #266 split() reutrn value inconsistency
Submitted: 1998-04-12 08:09 UTC Modified: 1998-05-30 09:37 UTC
From: sbedberg at ucdavis dot edu Assigned: rasmus (profile)
Status: Closed Package: Misbehaving function
PHP Version: 3.0 Release Candidate 3 OS: Win NT 4.0
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: sbedberg at ucdavis dot edu
New email:
PHP Version: OS:

 

 [1998-04-12 08:09 UTC] sbedberg at ucdavis dot edu
According to the documentation and my experience, the split()
function returns the an array of strings separated by the
given regexp, _but without the text of the regexp itself_.

However, it seems that if the regexp is found at the
beginning of the string to be separated, it is left in.

This seems similar to bug #9, which was supposedly resolved
in 3.0b4 (by the way, this bug happens in 3.0b4 as well as
3.0RC-3 under Win32).

--- EXAMPLE CODE -------------------------------------------
$remaining_line = array(
   'some text then <A Href="link">and then more text',
   'some more text terminated with <a href="',
   '<a href="another link" followed by text'
);

for ($i = 0; $i < 3; $i++) {

   $temp = split('<[[:space:]]*[Aa][[:space:]]*[Hh][Rr][Ee][Ff]'.
                    '[[:space:]]*=[[:space:]]*"[[:space:]]*',
                 $remaining_line[$i],
                 2);
   echo "($temp[0]) ($temp[1])<BR>\n";

}

--- OUTPUT -------------------------------------------------
(some text then ) (link">and then more text)
(some more text terminated with ) ()
() (a href="another link" followed by text)
------------------------------------------------------------

Note that the "a href=" text is removed from all lines
except the last. Interestingly, the leading "<" is stripped.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-05-30 09:37 UTC] rasmus
Ok, this split() bug has finally been crushed.  Good call
on it being similar to bug #9!  It was indeed.  In bug #9
I had fixed the case where the regex match was 1 char
long and at the start of the string, but I had forgotten
about the multi-character case.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC