note 91891 added to function.wordwrap

From: Date: Tue, 30 Jun 2009 22:58:15 +0000
Subject: note 91891 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-157733@lists.php.net to get a copy of this message
wordwrap() appears to have a bug: more than one space in a row is preserved when perhaps it shouldn't be. This causes indentation on subsequent lines. The following is a quick fix that will work on those occasions where you'll never have more than two spaces in a row (such as you type after a full stop). Anything more complex will probably require a regular expression to match one or more spaces after each linefeed and condense them down to a single space. <?php $paragraph = 'This paragraph should be word wrapped to 72 columns for each line shown. This is a limit imposed in honour of the glorious VT05.'; $paragraph = wordwrap($paragraph, 72); echo "<pre>{$paragraph}</pre>"; $paragraph = str_replace("\n ", "\n", $paragraph); // Compensate for a wordwrap() quirk that, when confronted with two spaces in a row with a split that occurs after the first, lets the second space indent the new line. echo "<pre>{$paragraph}</pre>"; ?> ---- Server IP: 92.48.74.199 Probable Submitter: 82.69.105.163 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/91891 Del: integrated -- https://master.php.net/note/delete/91891/integrated Del: useless -- https://master.php.net/note/delete/91891/useless Del: bad code -- https://master.php.net/note/delete/91891/bad+code Del: spam -- https://master.php.net/note/delete/91891/spam Del: non-english -- https://master.php.net/note/delete/91891/non-english Del: in docs -- https://master.php.net/note/delete/91891/in+docs Del: other reasons-- https://master.php.net/note/delete/91891 Reject -- https://master.php.net/note/reject/91891 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157733) next »