How PHP converts BR newline characters in HTML into line breaks in text input _php tutorial

Source: Internet
Author: User
PHP has a very good function: NL2BR (), the text box to convert the line to the HTML page
, but how to implement the HTML
is the newline character converted to a line break in a text box? Here are a few ways to help you solve this problem.

The PHP version adds the HTML
Line breaks convert to newline characters in text boxes:

function Br2nl ($text) {    return preg_replace ('//I
 
  
   
  ', ' ', $text);
 }
  

Or:

function Br2nl ($text) {    $text =preg_replace ('//I
 
  
   
  ', CHR), $text), return preg_replace ('//I ', ', $ text);}
 
  

JS version will be in the HTML
Line breaks convert to newline characters in text boxes:

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

Articles you may be interested in

    • PHP converts full-width characters in a string to half-width characters
    • PHP compressed HTML page code (clear spaces, line breaks, tabs, comment markers)
    • PHP converts consecutive spaces in a string to a space
    • JS limit can only input English letters and numbers, can not input Chinese and other special characters of the method
    • PHP compressed HTML page code reduces network data transfer, clear spaces, tabs, comment tags
    • A PHP classic tutorial book recommended for beginners in PHP
    • Summary of methods used by PHP to save arrays as text formats
    • PHP to determine whether the string is in English, pure Chinese, the method of combination of English

http://www.bkjia.com/PHPjc/764110.html www.bkjia.com true http://www.bkjia.com/PHPjc/764110.html techarticle PHP has a very good function: NL2BR (), the text box in the line to convert to the HTML page br/, but how to implement the HTML of the BR/newline character into a text box line break? ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.