Php how to convert the br line break in html to the line break in text input _ PHP Tutorial

Source: Internet
Author: User
Php converts the br line breaks in html to line breaks in text input. PHP has a very good function: nl2br (), which converts the line break in the text box to the br on the HTML page. but how can we convert the br line break in html to the line break in the text box? PHP has a very good function: nl2br (), which converts the line feed in the text box to
But how to implement
How about converting a line break to a line break in the text box? The following methods can help you solve this problem.

In PHP
Line breaks are converted to line breaks in the text box:

function br2nl($text){    return preg_replace('/
 
  /i','',$text);}
 

Or:

function br2nl($text){    $text=preg_replace('/
 
  /i',chr(13),$text);return preg_replace('/ /i',' ',$text);}
 

In JS
Line breaks are converted to line breaks in the text box:

function br2nl(txt){    var re=/(
 |
|
| )/g; var s=txt.replace(re,"\n"); return s; }
Articles you may be interested in
  • Php converts all-round characters in a string to half-width characters.
  • PHP compresses html webpage code (clear spaces, line breaks, tabs, comment tags)
  • Php converts multiple consecutive spaces in a string into one.
  • Js restrictions: only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
  • PHP compresses html webpage code to reduce the amount of network data transmitted, clear spaces, tabs, and comment mark
  • A classic php Tutorial book recommended for php beginners
  • Summary of methods for saving arrays as text formats in php
  • Php determines whether the string is full of English, pure Chinese, and a combination of Chinese and English

Transform (), convert the line feed in the text box to the br/in the HTML page, but how can we convert the br/line break in the html to the line break in the text box ?...

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.