syntaxe heredoc


/ Published in: PHP
Save to your folder(s)

for heredoc syntax (like perl)


Copy this code and paste it in your HTML
  1. <?php
  2. $str = <<<EOD
  3.   Exemple de chaîne
  4.   s'étalant sur
  5.   plusieurs lignes
  6.   avec la syntaxe heredoc
  7. EOD;
  8.  
  9. /* Exemple plus complexe, avec des variables. */
  10. class foo {
  11. var $foo;
  12. var $bar;
  13. function foo() {
  14. $this->foo = 'Foo';
  15. $this->bar = array('Bar1', 'Bar2', 'Bar3');
  16. }
  17. }
  18.  
  19. $foo = new foo();
  20. $name = 'MonNom';
  21.  
  22. echo <<<EOT
  23.   Mon nom est "$name". J'affiche des $foo->foo.
  24.   Maintenant, j'affiche un {$foo->bar[1]}.
  25.   Ceci se traduit par un 'A' majuscule : \x41
  26. EOT;
  27. ?>

URL: http://fr2.php.net/manual/fr/language.types.string.php#language.types.string.syntax.heredoc

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.