PHP 语法heredoc

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 语法heredoc相关的知识,希望对你有一定的参考价值。

<?php
$str = <<<EOD
  Exemple de chaîne
  s'étalant sur
  plusieurs lignes
  avec la syntaxe heredoc
EOD;

/* Exemple plus complexe, avec des variables. */
class foo {
   var $foo;
   var $bar;
   function foo() {
       $this->foo = 'Foo';
       $this->bar = array('Bar1', 'Bar2', 'Bar3');
   }
}

$foo = new foo();
$name = 'MonNom';

echo <<<EOT
  Mon nom est "$name". J'affiche des $foo->foo.
  Maintenant, j'affiche un {$foo->bar[1]}.
  Ceci se traduit par un 'A' majuscule : \x41
EOT;
?>

以上是关于PHP 语法heredoc的主要内容,如果未能解决你的问题,请参考以下文章