note 36983 added to function.strtr

From: Date: Wed, 29 Oct 2003 18:31:58 +0000
Subject: note 36983 added to function.strtr
Groups: php.notes 
Request: Send a blank email to php-notes+get-59485@lists.php.net to get a copy of this message
Here's a function to replace linebreaks to html <p> tags. This was initially designed to receive a typed text by a form in a "insert new notice" page and put in a database, then a "notice" page could get the text preformatted with paragraph tags instead of linebreaks that won't appear on browser. The function also removes repeated linebreaks the user may have typed in the form. function break_to_tags(&$text) { // find and remove repeated linebreaks $double_break = array("\r\n\r\n" => "\r\n"); do { $text = strtr($text, $double_break); $position = strpos($text, "\r\n\r\n"); } while ($position !== false); // find and replace remanescent linebreaks by <p> tags $change = array("\r\n" => "<p>"); $text = strtr($text, $change); } []'s Fernando ---- Manual Page -- http://www.php.net/manual/en/function.strtr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36983 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36983&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36983&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#59485) next »