P粉3110892792023-08-19 10:28:34
The content in double quotes will be parsed, but the content in single quotes will not be parsed:
$s = "dollars"; echo 'This costs a lot of $s.'; // This costs a lot of $s. echo "This costs a lot of $s."; // This costs a lot of dollars.
P粉7416783852023-08-19 00:19:38
PHP string can be specified not only in two ways, but also in four ways.
\'
, and to display a backslash, escape it with another backslash \\
Escape (so, yes, even single-quoted strings will be parsed). $type
and you want to echo "The $types are"
. This will look for the variable $types
. To solve this problem, use echo "The {$type}s are"
. Check out String Parsing to learn how to use array variables etc. <<<
. After this operator, provide an identifier, followed by a newline character. Then the string itself, and the same identifier is used again to close the reference. In this syntax, you don't need to escape quotes. <<<
sequence as heredoc, but the following identifier is enclosed in single quotes, such as <<<'EOT'
. No parsing is done in Nowdoc. Notice: Single quotes within single quotes and double quotes within double quotes must be escaped:
$string = 'He said "What\'s up?"'; $string = "He said \"What's up?\"";
speed:
no difference.
Please read a
Trusted Article from a core PHP developer. When it comes to testing, we should never take it for granted. It is important to understand that writing trustworthy tests and interpreting their results requires a lot of knowledge and experience. This means that most tests are fake. For example, in code like this
for($i=0;$i<100000;$i++) { 'string'; }The quoted string is parsed
only once , along with the entire script, and then converted to opcodes. Then do it a million times. Therefore, what it measures is not parsing. This is just the tip of the iceberg. With nanobenchmarks like this, it's nearly impossible to create a trustworthy test that won't be marred by some interfering side effects.