For beginners who don't have much coding experience,
first think about all the words in PHP (actually called symbols) there are several categories.
1.php,mysql two-side keywords and functions. For example Echo,print,mysql_connect and so on. These are certainly not quoted.
2. Constants. Novice may not use much, the benefit of the constant is global, penetrating function. It's faster, but the novice can temporarily ignore the constant.
3. Variables. The "$" number is the variable. You can set a value for a variable, such as a string of characters, a number, a logical (TRUE/False) value, and so on. You can also represent a set of values (arrays, objects, and so on)
4. Value. You typically set values for constants and variables. The assignment statement $a= ' ABC ', the right ' abc ' is the value.
5. Parameters of the function (in parentheses). Can be a constant, a variable, a value of three.
The relationship between a variable (constant) and a value is as varied as the following conditions.
"Color" and "red",
"Length" with 100,
"Date" and October 25, 2007 "
Two. What is the case with PHP quotes
In fact, only the 4th "value" need to use quotation marks, the function is only the value of the quotation marks. and only strings (date values can be treated as strings) need to use quotation marks. The number (not available), is true or false (cannot be used) exception.
Example
Three. The difference between a single quote and a double quote
In general, both are generic. But the double quotes internal variable resolves, and the single quotation mark is not resolved.
Example
So if there is only a pure string inside, use a single quotation mark (fast), the interior has something else (such as a variable), with a few more points.
Four. What to do if PHP quotes appear inside the string-about escaping.
For example, we want to output: I'm a genius.
It must be escaped at this time. Escape is to turn the signed symbol into meaningless characters.
This is normal, because the number turns any character behind it into meaningless symbols. In this case, the PHP parser simply does not look at the quotation marks behind the number.
Also, you can escape special symbols such as semicolons, $ symbols, and so on.
Five. Connection of strings.
This is a troublesome question. In general, variable values are directly enclosed in double quotes. Additional strings are superimposed with "." Character.
In a complex situation where curly braces are included, PHP knows that this is a complete thing, and the quotes inside it do not affect the outside quotation marks.
The mix with HTML is also very simple, it is best to form all the HTML in double quotation marks, PHP as far as possible in the habit of single quotation marks. This makes it easy to copy large pieces of HTML code, as long as the tail and the single quotation mark is the correct string. The HTML code for hundreds of lines doesn't have to worry about PHP quotes.
Summarize the guidelines for using PHP quotes
1. The value of the string is enclosed in quotation marks
Use single quotes as much as possible in 2.PHP, with double quotes in all HTML code
3. When you include variables, use double quotation marks to simplify the operation
4. In complex cases, wrap them in curly braces.
PHP quotes also have a use, sometimes need to generate a text file in PHP, newline character n needs double quotation marks to work, single quotation marks will be directly to the N as character output.
http://www.bkjia.com/PHPjc/446320.html www.bkjia.com true http://www.bkjia.com/PHPjc/446320.html techarticle for beginners who don't have much coding experience, first think about all the words in PHP (actually called symbols) in several categories. 1.php,mysql two-side keywords and functions. For example ECHO,PRINT,MYSQ ...