PHP – Conversiones – Convertir tags html BR to NL
Función que en un texto reemplaza los tags html <BR> por un de nueva línea «\n» . Así de esta forma el texto en html contiene los mismos párafos que en texto plano.
/**
* Class HelperArray
*/
abstract class HelperConvert
{
/**
* Sustitule el tab <br> html por un \n
*
* @param $str
*
* @return string
*/
public static function br2nl($str)
{
$regex = "#<[^>]+br.+?>#i";
preg_match_all( $regex, $str, $matches );
foreach ( $matches[ 0 ] as $match ) {
$str = str_replace($match, "<br>", $str);
}
$brs = array( '<br>', '<br/>', '<br />' );
$str = str_replace( "\r\n", "\n", $str );
$str = str_replace( "\n\r", "\n", $str );
$str = str_replace( "\r", "\n", $str );
$str = str_ireplace( $brs, "\n", $str );
return $str;
}
}
conv
