Bug #74617 [Com]: wordwrap ignores newlines

From: Date: Mon, 22 May 2017 15:12:35 +0000
Subject: Bug #74617 [Com]: wordwrap ignores newlines
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209228@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74617&edit=1 ID: 74617 Comment by: bob dot terrell at acordex dot com Reported by: bob dot terrell at acordex dot com Summary: wordwrap ignores newlines Status: Feedback Type: Bug Package: Strings related Operating System: Any PHP Version: 5.6.30 Assigned To: cmb Block user comment: N Private report: N New Comment: Sorry, I think I missed a character in the test script. Try this: <?php $str = "123456789 123456789\n123 123 123"; echo wordwrap($str, 25, "\n "); ?> Note the space after the newline in the replace string. What I'm trying to do is word wrap preformatted text and indent the line by one space if it's forced to wrap. I had expected that it would see the newline in the middle of the string and start the counter over from there. Is it perhaps treating the break parameter as the only string that should be considered a newline and ignoring the \n in the string? Perhaps this is a documentation problem. The documentation says "The line is broken using the optional break parameter." I took this to mean that if a line must be broken, that's the string to insert. Is it also the string that's searched for? If so, that isn't clear. Previous Comments: ------------------------------------------------------------------------ [2017-05-21 11:46:06] cmb@php.net I can't reproduce the described behavior, see <https://3v4l.org/Nm8nG>. Please provide details about the PHP version you are using. ------------------------------------------------------------------------ [2017-05-18 22:19:42] bob dot terrell at acordex dot com Description: ------------ wordwrap ignores newline characters when deciding how to wrap a string. Consider the following string: $str = "123456789 123456789\n123 123 123"; Using wordwrap($str, 25, "\n"), you would expect two lines, as you want to wrap each line to 25 characters. You actually get three, because it ignores the fact that a newline exists at the 20th character, and it wraps the string after the first "123" word. Test script: --------------- <?php $str = "123456789 123456789\n123 123 123"; echo wordwrap($str, 25, "\n"); ?> Expected result: ---------------- Expected output: 123456789 123456789 123 123 123 Actual result: -------------- Actual output: 123456789 123456789 123 123 123 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74617&edit=1

« previous php.bugs (#209228) next »