note 53403 modified in function.wordwrap by danbrown

From: Date: Sun, 17 May 2009 18:35:30 +0000
Subject: note 53403 modified in function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155140@lists.php.net to get a copy of this message
Yet-another-wordwrap-improvement... If you attempt to wordwrap() lines that already contain some line-breaks that you want to maintain, a simple wrapper around wordwrap can help. For example: <?php function preserve_wordwrap($tstr, $len = 75, $br = '\n') { $strs = explode($br,$tstr); $retstr = ""; foreach ($strs as $str) { $retstr .= wordwrap($str,$len,$br) . $br; } return $retstr; } ?> I used a function like this for pulling quotes for my email out of a mysql database and formatting them for use in an email. Some quotes had multiple lines (e.g. a short conversation-style quote) that I wanted to maintain yet still word-wrap correctly. [EDIT BY danbrown AT php DOT net: Contains a bugfix by (ajd AT cloudiness DOT com) on 13-JUN-05 to address the incorrect order of parameters passed to explode().] --was-- Yet-another-wordwrap-improvement... If you attempt to wordwrap() lines that already contain some line-breaks that you want to maintain, a simple wrapper around wordwrap can help. For example: function preserve_wordwrap($tstr, $len = 75, $br = '\n') { $strs = explode($tstr,$br); $retstr = ""; foreach ($strs as $str) { $retstr .= wordwrap($str,$len,$br) . $br; } return $retstr; } I used a function like this for pulling quotes for my email out of a mysql database and formatting them for use in an email. Some quotes had multiple lines (e.g. a short conversation-style quote) that I wanted to maintain yet still word-wrap correctly. http://php.net/manual/en/function.wordwrap.php

« previous php.notes (#155140) next »