note 10315 added to wordwrap

From: Date: Wed, 27 Dec 2000 18:14:26 +0000
Subject: note 10315 added to wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-9127@lists.php.net to get a copy of this message
The function has some problems dealing with HTML-Code. The following script preserves the html: $text = "put your text with &auml; $uuml; or &copy; here..."; $text = strtr($text, array_flip(get_html_translation_table(HTML_ENTITIES))); $text = wordwrap($text, 20, "\n", 0); $text = htmlentities($text); $text = nl2br($text); $text = str_replace("\n", "", $text); echo $text; What happens? &uuml; (ü) would read as 6 characters, where the browser only shows 1. This seemes the function doesn't work properly. The script translates the special chars first and after then the wrapping rolles back. A special role playes the \n char, which prevents the <br>-Tag to be converted in &lt;br&gt; I've also found, that "cut" has a third parameter "2", that leaves the last line unwrapped, if a word excided the line. This is not documented and may be a bug, but it me be a feature too. So it gives you the chance to deal with the unwrapped line in a special way, for example, include a hyphenation-function. Joerg Krause www.php.comzept.de www.joergkrause.de/krause http://www.php.net/manual/function.wordwrap.php

« previous php.notes (#9127) next »