RE: [SMARTY] need modifier to break up paragraphs

From: Date: Thu, 28 Nov 2002 09:06:50 +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-6582@lists.php.net to get a copy of this message
> 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.

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