Posted By

rmaltete on 10/05/06


Tagged

heredoc


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

rmaltete


syntaxe heredoc


 / Published in: PHP
 

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

for heredoc syntax (like perl)

  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. ?>

Report this snippet  

You need to login to post a comment.