Home > Backend Development > PHP Tutorial > Application of double quotes and single quotes in PHP_PHP Tutorial

Application of double quotes and single quotes in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:27:45
Original
980 people have browsed it

Whether you are writing JavaScript or PHP, you are always accustomed to using single quotes. But I encountered a problem while coding at home on the weekend. I need to filter the line breaks in the string through PHP. Follow the following method:

 $out = str_replace(array('rn', 'r', 'n'), '', $out);PHP provides three ways to define strings: single quotes, double quotes, local documents (English called here document or heredoc).

Single quotation mark:

Using single quotes is the most efficient method, because PHP does not check built-in variables and escape sequences in single-quoted strings. The only characters that need to be escaped are backslashes and single quotes themselves.

Double quotes:

Built-in variables and escape sequences are checked, but escaped single quotes are not recognized. This also shows what is wrong with the code at the beginning. The correct approach is to use double quotes to define the escape sequence for newlines:

 $out = str_replace(array("rn", "r", "n"), '', $out);Local document:

Check all built-in variables and escape sequences. Double quotes do not need to be escaped. For example:

echo <<

This is a "here document" example.

Just for test.

EOT; Simply record it to deepen your impression.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/815785.htmlTechArticleWhether you are writing JavaScript or PHP, you are always accustomed to using single quotes. But I encountered a problem when I was coding at home on the weekend. I need to filter the newline characters in the string through PHP, as follows...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template