Doc #74617 [Com]: wordwrap ignores newlines

From: Date: Mon, 22 May 2017 17:43:18 +0000
Subject: Doc #74617 [Com]: wordwrap ignores newlines
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14718@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: Open Type: Documentation Problem Package: Strings related Operating System: Any PHP Version: 5.6.30 Block user comment: N Private report: N New Comment: I'll leave a comment on the wordwrap page, but it might be a good idea to edit the documentation. I guess this can either be set to "not a bug" or "documentation problem." Previous Comments: ------------------------------------------------------------------------ [2017-05-22 16:01:59] cmb@php.net > Is it perhaps treating the break parameter as the only string > that should be considered a newline and ignoring the \n in the > string? That appears to be so, see <https://3v4l.org/72PPC>. ------------------------------------------------------------------------ [2017-05-22 15:12:27] bob dot terrell at acordex dot com 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. ------------------------------------------------------------------------ [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.doc.bugs (#14718) next »