note 10315 deleted from function.wordwrap by jimw

From: Date: Fri, 14 Dec 2001 20:37:55 +0000
Subject: note 10315 deleted from function.wordwrap by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22768@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

« previous php.notes (#22768) next »