Invalid newline character in the PHP string _php instance of a workaround with no wrapping line

Source: Internet
Author: User

For example, the following code:

Copy Code code as follows:
<?php
Echo ' hello\n ';
echo ' World ';
?>

The newline character in the program is output directly, and the line cannot be wrapped correctly, and the solution is to change the single quotation mark into double quotation marks:
Copy Code code as follows:
<?php
echo "hello\n";
echo "World";
?>

That's it! In fact, PHP's double quotes and single quotes, the difference between the simple generalization of double quotes in the variable can be resolved, single quotes is an absolute string.

With: Php to remove line wrapping three method code

Copy Code code as follows:
<?php
Change lines for different systems in PHP
The implementation of line wrapping between different systems is not the same
Linux with/N in Unix
MAC with/R
windows in order to reflect the difference with Linux is/r/n
So it's not the same way to implement the different platforms.
PHP has three ways to solve

1. Use Str_replace to replace line wrapping
$str = Str_replace (Array ("/r/n", "/R", "N"), "", $str);

2, the use of regular replacement
$str = preg_replace ('//s*/', ', ', $str);

3. Use PHP to define a good variable (recommended)
$str = Str_replace (Php_eol, ', $str);
?>

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.