note 52532 added to function.wordwrap

From: Date: Wed, 04 May 2005 22:08:45 +0000
Subject: note 52532 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-88940@lists.php.net to get a copy of this message
I found that wordwrap deletes the spaces it wraps on. If you want to break up a string which doesn't consist of words, you may find this behaviour undesirable, as I did when trying to wordwrap a Regular Expression to 80 characters (for display along with test string, matches, etc.). To preserve the spaces and still achieve a consistent cut length, you need to replace spaces with a suitable one-character replacement. I chose the ASCII non-printing character SUB (ASCII #26; some old telephone code meaning substitute): <?php $regex= str_replace(' ', chr(26), $regex); $regex= wordwrap($regex, 80, '<br />', TRUE); $regex= str_replace(chr(26), ' ', $regex); ?> (Of course, you need to replace 80 with your column length and '<br />' with your break string) ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52532 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52532&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52532&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52532&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52532&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52532&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52532&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88940) next »