// $str2 = 'hello 'jack''; // A certain string is a news title, and single quotes appear in the title,
// Therefore, if you want to appear in the string, you have to use escape to express it
// is used to escape single quotes, so what should I do if I really want to express it.
// Common interview questions
// 1: What is the difference between single and double quotes to define a string?
$age = 29;
$str1 = 'hello nr t $age';
$str2 = "hello nr t $age";
echo $str1,'
',$str2;
/*
Difference in escaping:
Single quotes, the system does not perform complex escaping,
Only escape ',\, others---output them as they are.
With double quotes, there are more escapes, ",\,r,n,t,$, etc.
Differences in variable interpretation:
Single quotes, do not use $ in strings for variable name analysis,
The double quotes will try to interpret $ as a variable name for parsing.
*/
// 2: Single and double quotes define strings, which one is faster?
// Answer: Single quotes are parsed faster because there is no need for too much escaping and variable parsing
// Question: When should single/double quotes be used?
/* www.2cto.com
Answer: Large paragraphs of text, such as news titles, text content, self-introduction, etc.
Use ', the analysis is fast.
But sometimes, you really need to include variables in a string,
For example, when piecing together sql statements
$id = 5;
$sql = "select * from user where id = $id";
// If you use a single quote at this time, the statement becomes ..id= $id, and sql will go wrong.
// At this time, it is appropriate to use double quotes. Parse $id, and the statement is parsed into ..id = 5;
*/
?>
http://www.bkjia.com/PHPjc/477762.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477762.htmlTechArticle[php] ?php /* Strings have already been discussed when talking about variables, why do we need to talk about them again? Answer :Before, I only introduced the variable type string, but did not go into depth about its definition, properties, functions, etc...