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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Sun Mar 29 22:01:26 2020 UTC