Detri Amelia Chandra
  • HOME
  • GIS
  • HTML
  • Bootstrap
  • CSS
  • Javascript
  • Ubuntu
  • Useful Tools
    • URL Redirect Tool
    • URL Download Encryptor
No Result
View All Result
Detriamelia.com
  • HOME
  • GIS
  • HTML
  • Bootstrap
  • CSS
  • Javascript
  • Ubuntu
  • Useful Tools
    • URL Redirect Tool
    • URL Download Encryptor
No Result
View All Result
Detriamelia.com
No Result
View All Result

5. PHP Echo and Print Statements

29/11/2019
in PHP, Programming
PHP Syntax, Variables and PHP Echo/Print

PHP Syntax, Variables and PHP Echo/Print

With PHP, there are two basic ways to get output: echo and print.
In this tutorial we use echo or print in almost every example. So, this chapter contains a little more info about those two output statements.

PHP echo and print Statements

echo and print are more or less the same. They are both used to output data to the screen.
The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.

The PHP echo Statement

The echo statement can be used with or without parentheses: echo or echo().

Display Text

The following example shows how to output text with the echo command (notice that the text can contain HTML markup):

1
2
3
4
5
6
<?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.";
?>

Display Variables

The following example shows how to output text and variables with the echo statement:

1
2
3
4
5
6
7
8
9
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
echo "<h2>" . $txt1 . "</h2>";
echo "Study PHP at " . $txt2 . "<br>";
echo $x + $y;
?>

The PHP print Statement

The print statement can be used with or without parentheses: print or print().

Display Text

The following example shows how to output text with the print command (notice that the text can contain HTML markup):

1
2
3
4
5
<?php
print "<h2>PHP is Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>

Display Variables

The following example shows how to output text and variables with the print statement:

1
2
3
4
5
6
7
8
9
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
print "<h2>" . $txt1 . "</h2>";
print "Study PHP at " . $txt2 . "<br>";
print $x + $y;
?>

 

Tags: PHPProgramming
ShareTweetShare

Related Posts

Learn Python Basics for Beginners: Easy Ways to Understand the Python Programming Language
Python

Learn Python Basics for Beginners: Easy Ways to Understand the Python Programming Language

Python is a high-level programming language that can be used to create a wide range of applications. Python was created...

09/08/2023
Database Table Relations Using Join Operations and the Classical Model
Belajar PHP

Database Table Relations Using Join Operations and the Classical Model

MySQL is a highly popular relational database in today's programming world. With features that allow for table-to-table relationships, MySQL databases...

09/08/2023
PHP Forms - Validation With Required Fields
PHP

14. PHP Forms – Validation With Required Fields

Hi everyone, this time we will discuss about PHP Validation using the Required Field. Not many people know, it turns...

15/02/2020
PHP Form Handling
PHP

13. New Performing PHP Form Handling

Detriamelia.Com - Running form functions in PHP is not difficult. By using the $ _POST and $ _GET methods it...

13/02/2020
Next Post
Detailed Explanation of PHP Data Types

6. Detailed Explanation of PHP Data Types

Understanding PHP Condition If Else, Elseif Statements

7. Understanding PHP Condition If Else, Elseif Statements

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Application of Jquery Mask to Numbers in HTML and PHP Forms

Application of Jquery Mask For Numbers in HTML and PHP Forms

23/04/2019
PHP Form Handling

13. New Performing PHP Form Handling

13/02/2020
Introduction to Python Programming: A Beginner's Guide

Introduction to Python Programming: A Beginner’s Guide

16/08/2023
PHP Syntax, Variables and PHP Echo/Print

4. PHP Syntax and PHP Variables

29/11/2019

Instagram Feed

    The Instagram Access Token is expired, Go to the Customizer > JNews : Social, Like & View > Instagram Feed Setting, to refresh it.
  • HOME
  • GIS
  • HTML
  • Bootstrap
  • CSS
  • Javascript
  • Ubuntu
  • Useful Tools
Detriamelia.Com

© 2022 Detri Amelia Chandra - IT Tips and Programming Tutorials.

No Result
View All Result
  • HOME
  • GIS
  • HTML
  • Bootstrap
  • CSS
  • Javascript
  • Ubuntu
  • Useful Tools
    • URL Redirect Tool
    • URL Download Encryptor