Home >Backend Development >PHP Problem >What are the representation methods of php strings?

What are the representation methods of php strings?

青灯夜游
青灯夜游Original
2021-07-08 16:05:163462browse

表示方法有:1、用单引号把字符包围起来,语法“'字符'”;2、用双引号把字符包围起来,语法“"字符"”;3、 heredoc语法结构,语法“572255f0f671d91e1cf7b24c0b47548a结构声明大段的不用解析的文本类似。

<?php
@header("Content-type: text/html; charset=utf-8"); 
 
$name = &#39;php&#39;;
function foo(){
	static $str = <<<&#39;EOS&#39;
$name
\n
\r
\t
\v
\e
\f
\
\\
\\\\\
\$name
\"
\&#39;
\x41
\072
EOS;
echo $str;
}
foo();
 
/* 含有变量的更复杂示例 */
class foo
{
    
	const cons= <<<&#39;EOD&#39;
cons
EOD;
	var $test= <<<&#39;EOD&#39;
"test"
EOD;
	var $bar;
    function foo()
    {
        $this->bar = array(&#39;Bar1&#39;, &#39;Bar2&#39;, &#39;Bar3&#39;);
    }
}
 
$foo = new foo();
echo foo::cons."\n";
echo <<<&#39;EOT&#39;
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn