php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31544 chunk_split() unexpected result
Submitted: 2005-01-13 18:43 UTC Modified: 2005-01-14 02:19 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: warcraft2002 at libero dot it Assigned:
Status: Not a bug Package: Strings related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: warcraft2002 at libero dot it
New email:
PHP Version: OS:

 

 [2005-01-13 18:43 UTC] warcraft2002 at libero dot it
Description:
------------
string chunk_split ( string body [, int chunklen [, string end]])

chunk_split() inserts end to the end of the string too, if the last chunk is long exactly as chunklen.
Following the definition, this is expected:
(quoted from the function page):
"It inserts end (defaults to "\r\n") every chunklen characters"

BUT, this can be unuseful for some procedures. I'm not sure if this behavior was expected by you or if is a bug/mistake.

Reproduce code:
---------------
$string="00001111";
$splitted=chunk_split($string,4," ");
echo $splitted;

Expected result:
----------------
echo $splitted returns "0000 1111 " (without the " and WITH the ending space. I expected "0000 1111" (without the ending space and without the " )

Actual result:
--------------
Actually I reach my expected result adding:
$splitted=rtrim($splitted);
before echoing...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-14 02:19 UTC] jed@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

"1111" counts as 4 (chunklen) characters, this is expected.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 20:01:36 2025 UTC