php converts the br newline character in html to the newline character in the text input

  • 2020-05-30 19:43:16
  • OfStack

Here are a few ways you can solve this problem.

PHP version will html in < br / > The newline character is converted to the newline character in the text box:


function br2nl($text){
    return preg_replace('/<br\\s*?\/??>/i','',$text);
}

Or:


function br2nl($text){
    $text=preg_replace('/<br\\s*?\/??>/i',chr(13),$text);
 return preg_replace('/&nbsp;/i',' ',$text);
}

JS version will html < br / > The newline character is converted to the newline character in the text box:


function br2nl(txt){
    var re=/(<br\/>|<br>|<BR>|<BR\/>)/g;
    var s=txt.replace(re,"\n");
    return s;                                  
}


Related articles: