How to use php echo function
php The echo function is used to output one or more strings. Its syntax is echo(strings). The parameter strings is required and refers to one or more strings to be sent to the output.
#How to use the php echo function?
Definition and usage
echo() function outputs one or more strings.
Note: The echo() function is not actually a function, so you don't have to use parentheses with it. However, if you want to pass more than one argument to echo(), using parentheses will generate a parsing error.
Tip: The echo() function is slightly faster than print().
Tip: The echo() function also has simplified syntax. Prior to PHP 5.4.0, this syntax only worked if the short_open_tag configuration setting was enabled.
Syntax
echo(strings)
Parameters
strings Required. One or more strings to send to the output.
Return value: No return value.
PHP version: 4
Instance 1
Output the value of the string variable ($str):
<?php $str = "Hello world!"; echo $str; ?>
Example 2
Output the value of the string variable ($str), including HTML tags:
<?php $str = "Hello world!"; echo $str; echo "<br>What a nice day!"; ?>
Example 3
Connect two string variables:
<?php $str1="Hello world!"; $str2="What a nice day!"; echo $str1 . " " . $str2; ?>
Example 4
Output the value of the array:
<?php $age=array("Peter"=>"35"); echo "Peter is " . $age['Peter'] . " years old."; ?>
Example 5
Output some text:
<?php echo "This text spans multiple lines."; ?>
Example 6
<?php echo 'This ','string ','was ','made ','with multiple parameters.'; ?>
Example 7
<?php $color = "red"; echo "Roses are $color"; echo "<br>"; echo 'Roses are $color'; ?>
Example 8
##Simplified syntax (only applies if the short_open_tag configuration setting is enabled):
<?php $color = "red"; ?> <p>Roses are <?=$color?></p>
The above is the detailed content of How to use php echo function. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
