PHP 5 echo/print Statements |
-- Learning More Than Just Technology, But Also Dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
PHP Tutorial
- PHP Tutorial
- PHP Introduction
- PHP Installation
- PHP Syntax
- PHP Variables
- PHP echo/print
- PHP EOF(heredoc)
- PHP Data Types
- PHP Type Comparisons
- PHP Constants
- PHP String
- PHP Operators
- PHP If...Else
- PHP Switch
- PHP Arrays
- PHP Array Sorting
- PHP Superglobals
- PHP While Loop
- PHP For Loop
- PHP Functions
- PHP Magic Constants
- PHP Namespaces
- PHP OOP
- PHP Quiz
PHP Forms
- PHP Forms
- PHP Form Validation
- PHP Form - Required Fields
- PHP Form - Validate Email and URL
- PHP Complete Form Example
- PHP $_GET Variable
- PHP $_POST Variable
PHP Advanced
- PHP Multidimensional Arrays
- PHP Date
- PHP Include
- PHP File
- PHP File Upload
- PHP Cookie
- PHP Session
- PHP E-mail
- PHP Secure E-mail
- PHP Error
- PHP Exception
- PHP Filters
- PHP Advanced Filters
- PHP JSON
PHP 7 New Features
PHP Database
- PHP MySQL Introduction
- PHP MySQL Connect
- PHP MySQL Create Database
- PHP MySQL Create Table
- PHP MySQL Insert Data
- PHP MySQL Insert Multiple Data
- PHP MySQL Prepared Statements
- PHP MySQL Read Data
- PHP MySQL Where
- PHP MySQL Order By
- PHP MySQL Update
- PHP MySQL Delete
- PHP ODBC
PHP XML
PHP and AJAX
PHP Reference
- PHP Array
- PHP Calendar
- PHP cURL
- PHP Date
- PHP Directory
- PHP Error
- PHP Filesystem
- PHP Filter
- PHP FTP
- PHP HTTP
- PHP Libxml
- PHP Mail
- PHP Math
- PHP Misc
- PHP MySQLi
- PHP PDO
- PHP SimpleXML
- PHP String
- PHP XML
- PHP Zip
- PHP Timezones
- PHP Image Processing
- PHP RESTful
- PHP PCRE
- PHP Available Functions
- PHP Composer
Explore Further
- Scripting Languages
- Computer Science
- Web Services
- Software
- Web Design & Development
- Programming Languages
- Programming
- Web Service
- Development Tools
- Scripting
PHP 5 echo and print Statements
In PHP, there are two basic output methods: echo and print.
In this chapter, we will discuss the usage of these two statements in detail and demonstrate how to use echo and print with examples.
PHP echo and print Statements
Differences between echo and print:
echo- Can output one or more stringsprint- Can only output one string, and its return value is always 1
Tip: echo is faster than print. echo has no return value, while print has a return value of 1.
PHP echo Statement
echo is a language construct, so you can use it with or without parentheses: echo or echo().
Displaying Strings
The following example demonstrates how to use the echo command to output a string (the string can contain HTML tags):
Example
<?php
echo "<h2>PHP is fun!</h2>";
echo "Hello world!<br>";
echo "I want to learn PHP!<br>";
echo "This is a string, using multiple parameters.";
?>
Displaying Variables
The following example demonstrates how to use the echo command to output variables and strings:
Example
<?php
$txt1 = "Learning PHP";
$txt2 = ".COM";
$cars = array("Volvo", "BMW", "Toyota");
echo $txt1;
echo "<br>";
echo "Learning PHP at $txt2";
echo "<br>";
echo "My car brand is {$cars}";
?>
PHP print Statement
print is also a language construct, and you can use parentheses or not: print or print().
Displaying Strings
The following example demonstrates how to use the print command to output a string (the string can contain HTML tags):
Example
<?php
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I want to learn PHP!";
?>
Displaying Variables
The following example demonstrates how to use the print command to output variables and strings:
Example
<?php
$txt1 = "Learning PHP";
$txt2 = ".COM";
$cars = array("Volvo", "BMW", "Toyota");
print $txt1;
print "<br>";
print "Learning PHP at $txt2";
print "<br>";
print "My car brand is {$cars}";
?>
YouTip