English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Custom Function br2nl Method to Convert br Line Breaks in HTML to Line Breaks in Text Input [and Function nl2br Function Opposite]

This article gives an example of php custom function br2nl implements the method of converting HTML line breaks br

The following methods will help you solve this problem.

The PHP version converts <br /Convert line breaks to text box line breaks:

The code is as follows:

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

or

The code is as follows:

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

Appendix:

The JS version converts <br /Convert line breaks to text box line breaks:

The code is as follows:

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

Readers who are interested in more PHP-related content can check the special topic of this site: 'Summary of PHP Operators and Operator Usage', 'Summary of php string (string) usage', 'PHP Basic Syntax Tutorial', 'php object-oriented program design tutorial', 'php+mysql database operation tutorial and php common database operation skills summary

I hope the content described in this article will be helpful to everyone in PHP program design.

Statement: The content of this article is from the network, the copyright belongs to the original author, the content is contributed and uploaded by Internet users spontaneously, this website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please send an email to codebox.com (replace # with @ when sending an email) to report any violations, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.

You May Also Like