|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #22487 wordwrap removes space at break, could be optional?
Submitted: 2003-03-01 05:52 UTC Modified: 2017-11-05 04:22 UTC
Avg. Score:4.2 ± 0.7
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (40.0%)
From: mikael at whip3 dot net Assigned:
Status: No Feedback Package: *General Issues
PHP Version: * OS: *
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: mikael at whip3 dot net
New email:
PHP Version: OS:


 [2003-03-01 05:52 UTC] mikael at whip3 dot net
The function wordwrap removes on space character if a break occurs between two words. This is not always desired behavior.

For example:

echo wordwrap('abc abc abc    abc', 13, 'X', 1);

Note: 4 spaces between last pair

Results in:
abc abc abc  X abc

Two spaces left before the break and one after. One space gets removed. The same happens if we only have one space where a line break occurres, leaving us with only a line break between the words.

/ mikael


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-03 08:57 UTC] breiteseite1337 at gmail dot com
I fully agree with mikael. An optional parameter which controls this behaviour would be very useful.

For example: You create a ics/ical file and you want to break after 75 characters (

wordwrap could make that easy. But it may remove spaces. So your links may break and words may get unintentionally concatenated.

So a extra parameter makes sense in my opinion.


P.S.: a workaround for the above-mentioned problem is to replace the whitespace character with an extra symbol (e.g. '^'), wordwrap() and replace the extra symbol back to a whitespace.
 [2014-03-11 13:19 UTC]
-Package: Feature/Change Request +Package: *General Issues
 [2014-03-11 13:19 UTC]
This would accomplish what you want without using `wordwrap()`.

echo join("X", str_split($str, 13));
 [2017-10-24 02:23 UTC]
-Status: Open +Status: Feedback -Operating System: Windows XP +Operating System: * -PHP Version: 4.3.0 +PHP Version: *
 [2017-10-24 02:24 UTC]
Is this still an issue with PHP7+?
 [2017-11-05 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Dec 09 16:01:27 2023 UTC