Raspberry Pi_Eng_24.4.5 Output


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


24.4.5  Output

 

You can use "echo" and "print" commands to print processing results in PHP. Both perform almost the same function. The text to be processed may include an HTML tag.

 

24.4.5.1    "echo" Command

 

"echo" command has no return value and can process several parameters simultaneously.

 

echo   parameter, parameter

echo (  parameter, parameter )

 

[Used Example]

Below is a case of outputting simple texst.

 

<?php

echo "<h2>PHP is Fun!</h2>";

echo "Hello world!<br>";

echo "I'm about to learn PHP!<br>";

echo "This ", "string ", "was ", "made ", "with multiple parameters.";

?> 

 

The following example print text and variable with "echo" command.

 

<?php

$txt1 = "Learn PHP";

$txt2 = "W3Schools.com";

$x = 5;

$y = 4;

echo "<h2>$txt1</h2>";

echo "Study PHP at $txt2<br>";

echo $x + $y;

?>


 

24.4.5.2    "print" Command

 

"print" command returns value "1", so it can be used in an expression, and can process only one parameter. Use the following format.

 

print     parameter

print  (  parameter   )

 

[Used Example]

The following example prints simple text using "print" command.

 

<?php

      print "<h2>PHP is Fun!</h2>";

      print "Hello world!<br>";

      print "I'm about to learn PHP!";

?>  

 

The following example prints text and variables using "print" command.

 

<?php

      $txt1 = "Learn PHP";

      $txt2 = "W3Schools.com";

      $x = 5;

      $y = 4;

 

      print "<h2>$txt1</h2>";

      print "Study PHP at $txt2<br>";

      print $x + $y;

?>