search
HomeBackend DevelopmentPHP ProblemWhat are the two basic output methods in php

What are the two basic output methods in php

Nov 11, 2021 pm 07:05 PM
echophpprintOutput method

The two basic output methods of php are "echo" and "print". Echo is used to output one or more strings and can accept multiple parameters and has no return value. The syntax is "echo($str)"; while print is used to output a string and can only accept one parameter and has a return value. The syntax is "echo($str)". "print($str)".

What are the two basic output methods in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, There are two basic output methods: echo and print.

Difference between echo and print

  • echo - Outputs one or more strings, can accept multiple arguments and No return value
  • print - can only output a string, can only accept one parameter and have a return value, and always returns 1

Tip: echo is slightly faster than print because It returns no value.

PHP echo statement

1.echo is a language structure and can be used with or without parentheses: echo or echo();

2. Display string , the following example shows how to use the echo command to display different strings (please also note that the string can contain HTML tags)

<?php
echo "<h2 id="PHP-nbsp-is-nbsp-fun">PHP is fun!</h2>";
echo(123);
echo "<br>";
echo("我爱php");
echo "<br>";
echo "Hello world!<br>";
echo "I&#39;m about to learn PHP!<br>";
echo "This", " string", " was", " made", " with multiple parameters.";
?>

Effect:

PHP is fun!
123
我爱php
Hello world!
I&#39;m about to learn PHP!
This string was made with multiple parameters.

3.Display variables, the following example shows how to use the echo command to display strings and variables;

<?php
$txt1="Learn PHP";
$txt2="W3School.com.cn";
$cars=array("Volvo","BMW","SAAB");

echo $txt1;
echo "<br>";
echo "Study PHP at $txt2 <br />";
echo "My car is a {$cars[0]}";
?>

Effect:

Learn PHP
Study PHP at W3School.com.cn 
My car is a Volvo

PHP print statement

1. Print is also a language structure and can be used with or without parentheses: print or print().

2. Display strings. The following example shows how to use the print command to display different strings (please note that the string can contain HTML tags):

<?php
print "<h2 id="PHP-nbsp-is-nbsp-fun">PHP is fun!</h2>";
print "Hello world!<br>";
print "I&#39;m about to learn PHP!";
?>

Effect:

PHP is fun!
Hello world!
I&#39;m about to learn PHP!

3. Display variables. The following example shows how to use the print command to display strings and variables:

<?php
$txt1="Learn PHP";
$txt2="W3School.com.cn";
$cars=array("Volvo","BMW","SAAB");

print $txt1;
print "<br>";
print "Study PHP at $txt2 <br>";
print "My car is a {$cars[0]}";
?>

Effect:

Learn PHP
Study PHP at W3School.com.cn 
My car is a Volvo

Recommended learning: "PHP Video Tutorial

The above is the detailed content of What are the two basic output methods in php. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool