Facendo una ricerva sul sito di php ho trovato questo:
Codice PHP:
Here is a variant of nl2br that does not insert newlines inside HTML tags.
<?php
function www_nl2br ($testo)
{
# Example of preg_match_all's result:
# Array (
# [0] => Array (
# [0] => First line
# [1] => See also [url="http://www.polimi.it/"][url]www.polimi.it[/url][/url]
# [2] => Third line [url="http://www.polimi.it/"][url]www.polimi.it[/url][/url]
# )
# )
#
# The output then is
# First line
# See also [url="http://www.polimi.it/"][url]www.polimi.it[/url][/url]
# Third line [url="http://www.polimi.it/"][url]www.polimi.it[/url][/url]
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
", $result[0]);
}
?>
Non ho ben capito come applicarla...