php basics
PHP echo double quotes and single quotes
PHP echo double quotation marks and single quotation marks use the same technique, because single quotation marks or double quotation marks or duplicate quotation marks in echo output will cause PHP to generate error messages. Of course, single quotation marks or double quotation marks cannot be echoed smoothly . The echo error message is as follows:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in ...
PHP designers usually use backslashes (\) to escape characters, so that single quotation marks (') or double quotation marks (") can be echoed out. Please refer to the example for actual application.PHP echo double quotation mark and single quotation mark example
<?php
echo'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; //Web page encoding declaration
echo'echo single quote:';
echo '\' ';
echo'<br>';
echo'echo out of double quotes:';
echo "\" ";
?>
Example outputecho'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; //Web page encoding declaration
echo'echo single quote:';
echo '\' ';
echo'<br>';
echo'echo out of double quotes:';
echo "\" ";
?>
Echo out of single quotes: '
Echo out of double quotes: "
The content of the echo in the first line of the example is the encoding of the webpage. The purpose is to make the subsequent traditional Chinese display normally. The <br> of the echo in the fourth line is the line break of HTML , and the focus is on the single quote (') and double quote (") in the echo . In these two lines, use the escape character (\) to escape the quotation marks, so that it can be echoed out. Don’t pay attention to that, each escape character (\) can only escape one quotation mark, in other words , To echo two quotation marks, you need to use double escape characters (\), written like this "\'\'", in addition, when echo single quotation marks, the outer layer of the echo output string should also be wrapped in single quotation marks When echo double quotes, the outermost layer of the output string should be wrapped with double quotes.Echo out of double quotes: "
Post a Comment
0 Comments