print_basic.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. Test print() function : basic functionality
  3. --FILE--
  4. <?php
  5. echo "*** Testing print() : basic functionality ***\n";
  6. echo "\n-- Iteration 1 --\n";
  7. print("Hello World");
  8. echo "\n-- Iteration 2 --\n";
  9. print "print() also works without parentheses.";
  10. echo "\n-- Iteration 3 --\n";
  11. print "This spans
  12. multiple lines. The newlines will be
  13. output as well";
  14. echo "\n-- Iteration 4 --\n";
  15. print "This also spans\nmultiple lines. The newlines will be\noutput as well.";
  16. echo "\n-- Iteration 5 --\n";
  17. print "escaping characters is done \"Like this\".";
  18. // You can use variables inside of a print statement
  19. $foo = "foobar";
  20. $bar = "barbaz";
  21. echo "\n-- Iteration 6 --\n";
  22. print "foo is $foo"; // foo is foobar
  23. // You can also use arrays
  24. $bar = array("value" => "foo");
  25. echo "\n-- Iteration 7 --\n";
  26. print "this is {$bar['value']} !"; // this is foo !
  27. // Using single quotes will print the variable name, not the value
  28. echo "\n-- Iteration 8 --\n";
  29. print 'foo is $foo'; // foo is $foo
  30. // If you are not using any other characters, you can just print variables
  31. echo "\n-- Iteration 9 --\n";
  32. print $foo; // foobar
  33. echo "\n-- Iteration 10 --\n";
  34. $variable = "VARIABLE";
  35. print <<<END
  36. This uses the "here document" syntax to output
  37. multiple lines with $variable interpolation. Note
  38. that the here document terminator must appear on a
  39. line with just a semicolon no extra whitespace!\n
  40. END;
  41. ?>
  42. --EXPECT--
  43. *** Testing print() : basic functionality ***
  44. -- Iteration 1 --
  45. Hello World
  46. -- Iteration 2 --
  47. print() also works without parentheses.
  48. -- Iteration 3 --
  49. This spans
  50. multiple lines. The newlines will be
  51. output as well
  52. -- Iteration 4 --
  53. This also spans
  54. multiple lines. The newlines will be
  55. output as well.
  56. -- Iteration 5 --
  57. escaping characters is done "Like this".
  58. -- Iteration 6 --
  59. foo is foobar
  60. -- Iteration 7 --
  61. this is foo !
  62. -- Iteration 8 --
  63. foo is $foo
  64. -- Iteration 9 --
  65. foobar
  66. -- Iteration 10 --
  67. This uses the "here document" syntax to output
  68. multiple lines with VARIABLE interpolation. Note
  69. that the here document terminator must appear on a
  70. line with just a semicolon no extra whitespace!