note 121113 added to function.wordwrap
| From: | tuxedobob | Date: | Mon, 22 May 2017 17:55:59 +0000 |
| Subject: | note 121113 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209095@lists.php.net to get a copy of this message | ||
It should be noted that the behavior of the $break parameter is poorly explained.
If you specify the $break parameter, then *that string defines what the function considers a
"newline"*.
Consider the following string:
$str = "Rumplestiltskin Schwartzmenikoff
1534 Gingerbread Lane
Black Forest, Germany";
You are trying to fit this address into a space that only allows for 22 characters, but you want it
clear that you're continuing a previous line, so you want a space added. You might try this:
$str = wordwrap($str, 22, "\n>");
If you did that, you would end up with the following output:
"Rumplestiltskin
>Schwartzmenikoff
1534
>Gingerbread Lane
Black
>Forest, Germany"
This is because when you pass it a third parameter of "\n>", it assumes that entire
string is a newline character. It's no longer using "\n". In your output, of course,
\n is still a newline, so it appears to have extra lines.
If you're looking to wordwrap a multi-line string with something besides a newline character,
make sure all existing linebreaks are already delineated with the string you pass to wordwrap().
----
Server IP: 72.52.91.14
Probable Submitter: 70.88.203.198
----
Manual Page -- http://php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/121113
Del: integrated -- https://master.php.net/note/delete/121113/integrated
Del: useless -- https://master.php.net/note/delete/121113/useless
Del: bad code -- https://master.php.net/note/delete/121113/bad+code
Del: spam -- https://master.php.net/note/delete/121113/spam
Del: non-english -- https://master.php.net/note/delete/121113/non-english
Del: in docs -- https://master.php.net/note/delete/121113/in+docs
Del: other reasons-- https://master.php.net/note/delete/121113
Reject -- https://master.php.net/note/reject/121113
Search -- https://master.php.net/manage/user-notes.php