note 112563 added to function.wordwrap

From: Date: Sun, 30 Jun 2013 03:58:09 +0000
Subject: note 112563 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-195402@lists.php.net to get a copy of this message
Note that wordwrap() will ONLY break on an empty space " ", so if you have <?php wordwrap("this/is#a*really-long^line", 5, PHP_EOL); ?> This will not be broken up even though the single line is longer than the maximum width. It also will not break the string on any special characters either, only empty spaces. Another thing to note (even if it is a bit obvious) is that when breaking the words up, you will actually lose the last empty space, so you can't just concatenate the strings back together again. Here is a simple example that won't work: <?php $string = "Some text here that will be broken up"; $lines = wordwrap($string, 10, PHP_EOL); echo str_replace(PHP_EOL, '', $lines); // Produces: Some texthere thatwill bebroken up ?> Just remember to keep track of where you need to re-add your empty spaces. In this example, of course, you could just do str_replace(PHP_EOL, ' ', $lines) ---- Server IP: 69.147.83.199 Probable Submitter: 186.15.1.63 ---- Manual Page -- http://php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/112563 Del: integrated -- https://master.php.net/note/delete/112563/integrated Del: useless -- https://master.php.net/note/delete/112563/useless Del: bad code -- https://master.php.net/note/delete/112563/bad+code Del: spam -- https://master.php.net/note/delete/112563/spam Del: non-english -- https://master.php.net/note/delete/112563/non-english Del: in docs -- https://master.php.net/note/delete/112563/in+docs Del: other reasons-- https://master.php.net/note/delete/112563 Reject -- https://master.php.net/note/reject/112563 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195402) next »