Funcion br2nl en php

PHP carece de la función inversa de nl2br, la funcion nl2br de php convierte todos los saltos de linea a salto de linea html <br />

Por eso la función siguiente br2nl, conviete los <br /> a salto de linea

Declaración de la función br2nl

function br2nl($string, $line_break=PHP_EOL) {
    $patterns = array("/(<br>|<br \/>|<br\/>)\s*/i","/(\r\n|\r|\n)/");
    $replacements = array(PHP_EOL,$line_break);
    $string = preg_replace($patterns, $replacements, $string);
    return $string;
}

Uso de la función br2nl

echo br2nl($Texto)
Tagged with: , ,
Posted in Code Snippets, PHP Snippets

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">