note 42952 added to function.nl2br

From: Date: Fri, 04 Jun 2004 14:36:33 +0000
Subject: note 42952 added to function.nl2br
Groups: php.notes 
Request: Send a blank email to php-notes+get-70707@lists.php.net to get a copy of this message
Here is a variant of nl2br that does not insert newlines inside HTML tags. function www_nl2br ($testo) { # Example of preg_match_all's result: # Array ( # [0] => Array ( # [0] => First line # [1] => See also <a NEWLINE # href="http://www.polimi.it/">www.polimi.it</a> # [2] => Third line <a href="http://www.polimi.it/">www.polimi.it</a> # ) # ) # # The output then is # First line<br/> # See also <a # href="http://www.polimi.it/">www.polimi.it</a><br/> # Third line <a href="http://www.polimi.it/">www.polimi.it</a><br/> preg_match_all ('/ (?> (?> [^<\n]*) # testo fuori dai tag (?> <[^>]*>)* # e tag se serve )* # ad libitum (\n|\Z) # fino a fine linea /xs', $testo, $result); return implode ("\n<br/>", $result[0]); } ---- Manual Page -- http://www.php.net/manual/en/function.nl2br.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42952 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42952&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42952&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#70707) next »