Solution to the problem of replacing line breaks with spaces

Source: Internet
Author: User
To solve the problem of replacing line breaks with spaces, replace space with & amp; nbsp; line breaks with & lt; br & gt; doubt: replace space with & quot; whether the s line break is n or the rn environment is in a non-IR browser. Statement of solution, all replaced at one time. Set the content to $ txt ------ solution ------------------ PHPcodeechopreg_r line break space replacement problem
I want to replace spaces

Replace line breaks


Doubt:
Enter "" or \ s as a space when replacing

Whether the line break is \ n or \ r \ n

The environment is in a non-IR browser

Internet Explorer does not need to be considered.

Statement of solution, all replaced at one time.

Set content to $ txt

------ Solution --------------------
PHP code
Echo preg_replace (array ('//', '/[\ r \ n] +/'), array ('','
'), $ String );
------ Solution --------------------
$ Changeset = array ('\ r \ n' =>'
', ''=>' $ Nbsp ;');
$ Str = strtr ($ str, $ changeset );

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.