Usage analysis of PHP double quotes and single quotes

WBOY
Release: 2016-07-25 08:56:39
Original
1459 people have browsed it
This article shares a problem I encountered with double quotes and single quotes in PHP during my actual work, along with a solution. Friends in need can use it as a reference. To filter newlines in strings through PHP, you usually do this:
<?php $out = str_replace(array('\r\n', '\r', '\n'), '', $out);
Copy after login
PHP provides three ways to define strings: single quotes, double quotes, and local documents (called here document or heredoc in English). apostrophe: 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:
<?php $out = str_replace(array("\r\n", "\r", "\n"), '', $out);
heredoc:
Copy after login
Check all built-in variables and escape sequences, double quotes do not need to be escaped. For example:
<?php echo <<<EOT
this is a "here document" example.
just for test.
EOT;
Copy after login


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