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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
32 + 20 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 14:01:31 2024 UTC