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

About double quotes and single quotes in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 14:58:23961browse

Whether 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 needed 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 a here document or heredoc).

Single quotes:
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:
will check built-in variables and escape sequences, but will not recognize escaped single quotes. This also illustrates the error in 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 documentation:
Check all built-in variables and escape sequences, double quotes do not need to be escaped righteous. For example:

echo <<this is a "here document" example.
just for test.
EOT;Simple record to deepen the impression.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363842.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 line breaks in the string through PHP. Follow the following...
Statement:
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