note 91891 deleted from function.wordwrap by danbrown

From: Date: Wed, 01 Jul 2009 01:12:28 +0000
Subject: note 91891 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157737@lists.php.net to get a copy of this message
Note Submitter: Zoe Blade ---- 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>"; ?>

« previous php.notes (#157737) next »