RE: [SMARTY] need modifier to break up paragraphs

From: Date: Thu, 28 Nov 2002 16:08:25 +0000
Subject: RE: [SMARTY] need modifier to break up paragraphs
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6593@lists.php.net to get a copy of this message
Thanks, I'll check it out later. And a Happy Thanksgiving to all those in the U.S... -----Original Message----- From: Ben Phillips [mailto:ben@inchima.com] Sent: Thursday, November 28, 2002 4:07 AM To: dickens@dreamgear.com; smarty-general@lists.php.net Subject: RE: [SMARTY] need modifier to break up paragraphs > I find myself doing this in php: > > $search = "\n"; > $replace = "<br />"; > $smarty->assign("text",str_replace($search, $replace, $text)); > > It seems to me this might be better done by a modifier in Smarty. for a start, in php you shouldn't be doing that. the nl2br() function is much better suited to your needs. http://www.php.net/nl2br > In my application (a single-purpose CMS) text is entered in a > form and stored in a database. When the text is retrieved > for display, I want it to be displayed with the original line > breaks, so I replace all the newlines with "<br />". i dunno if this is the best way to do this, but you can do a simple regex in smarty: {$text|regex_replace:"/[\r\t\n]/":"<br />"} you can also ensure two line breaks represent a new paragraph by doing (if doing both this and the above, then do this one first): {$text|regex_replace:"/[\r\t\n][\r\t\n]/":"</p><p>"} benji. -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#6593) next »