Home > Article > Backend Development > About double quotes and single quotes in PHP_PHP Tutorial
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 <<
just for test.
EOT;Simple record to deepen the impression.