note 78883 modified in function.nl2br by thiago

From: Date: Thu, 05 Mar 2009 12:15:47 +0000
Subject: note 78883 modified in function.nl2br by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151516@lists.php.net to get a copy of this message
Simple function that converts more than one <br>,<br/>,<br />... to a <p></p>. Maybe it's useful for someone =) <?php function br2p($string) { return preg_replace('#<p>[\n\r\s]*?</p>#m', '', '<p>'.preg_replace('#(<br\s*?/?>){2,}#m', '</p><p>', $string).'</p>'); } ?> Useful used with nl2br: <?php br2p(nl2br(...)); ?> --was-- Simple function that converts more than one <br>,<br/>,<br />... to a <p></p>. Maybe it's useful for someone =) function br2p($string) { return preg_replace('#<p>[\n\r\s]*?</p>#m', '', '<p>'.preg_replace('#(<br\s*?/?>){2,}#m', '</p><p>', $string).'</p>'); } Useful used with nl2br: br2p(nl2br(...)); http://php.net/manual/en/function.nl2br.php

« previous php.notes (#151516) next »