Home >Backend Development >PHP Problem >What are the representation methods of php strings?
表示方法有:1、用单引号把字符包围起来,语法“'字符'”;2、用双引号把字符包围起来,语法“"字符"”;3、 heredoc语法结构,语法“572255f0f671d91e1cf7b24c0b47548a结构声明大段的不用解析的文本类似。
<?php @header("Content-type: text/html; charset=utf-8"); $name = 'php'; function foo(){ static $str = <<<'EOS' $name \n \r \t \v \e \f \ \\ \\\\\ \$name \" \' \x41 \072 EOS; echo $str; } foo(); /* 含有变量的更复杂示例 */ class foo { const cons= <<<'EOD' cons EOD; var $test= <<<'EOD' "test" EOD; var $bar; function foo() { $this->bar = array('Bar1', 'Bar2', 'Bar3'); } } $foo = new foo(); echo foo::cons."\n"; echo <<<'EOT' nowdoc中不支持复杂的格式如: \$foo->test=> $foo->test. {\$foo->bar[1]}=>{$foo->bar[1]}. EOT; ?>推荐学习:《PHP视频教程》
The above is the detailed content of What are the representation methods of php strings?. For more information, please follow other related articles on the PHP Chinese website!