Summary _php tutorial for replacing line break methods in PHP

Source: Internet
Author: User
Tags how to use curl

Summary of alternative line break methods in PHP


PHP replaces the line break method summary, PHP has three ways to solve.

1. Use Str_replace to replace line breaks

$str =str_replace (Array ("\ r \ n", "\ r", "\ n"), "", $str);

2. Use regular replacement

$str =preg_replace ('//s*/', ', $str);

3. Use PHP-defined variables (recommended)

$str =str_replace (Php_eol, ", $STR);

To the foreground can display the line break, nl2br the direction function reference PHP manual

$str = "ABEFC"; Echo nl2br ($STR);

The output HTML code is as follows:

A

B

E

F

C

Articles you may be interested in

    • PHP uses regular filters to filter various tags, spaces, line break codes
    • How PHP converts BR newline characters in HTML to line breaks in text input
    • PHP compressed HTML page code (clear spaces, line breaks, tabs, comment markers)
    • CSS control English, Chinese forced line and non-newline code
    • PHP string substitution function str_replace faster than preg_replace
    • PHP replaces only once, controls the number of replacements
    • PHP compressed HTML page code reduces network data transfer, clear spaces, tabs, comment tags
    • How to use Curl's post submission data in PHP and get a summary of how to get Web page data

http://www.bkjia.com/PHPjc/1072764.html www.bkjia.com true http://www.bkjia.com/PHPjc/1072764.html techarticle PHP replaces line break method Summary of the method of replacing newline characters in PHP, PHP has three ways to solve. 1. Use Str_replace to replace newline $str =str_replace ("\ r \ n", "\ r", "\ ...

  • 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.