PHP Echo
When we want to display data on a web page, we need to use function echo ().
Let's say we need to display Hello Web ! on a web page, for that we need to put the string in quotes after operator echo.
<?php
echo 'Hello Web !';
//Output a string Hello Web
?>
The echo () function is used to output the given argument. It can output all types of data, and multiple outputs can be made with only one echo () command.
The echo is not a function (it is a language construct), so you do not have to use brackets with it.
If you want to pass more than one parameter to echo, the parameters must not be enclosed within brackets.
For example.
<?php
echo 'Hello Web !';
//Output a string Hello Web
echo ('Hello Web !');
//Output a string Hello Web
echo $variable;
//Output a value of $variable
echo 'string ' . $variable. ' other string' ;
//Output a string, then a variable, then a string
?>
For the output of data, we can use single and double-quotes.
If we use single quotes, the data date between the quotes always will be displayed as a string!
<?php
$variable = 'Hello Web !' ;
echo '$variable';
//Output a string $variable
echo $variable;
//Output a string Hello Web
// For the number, we can not use quotes
echo '3' . "3" . 3;
//Output 3 3 3
?>
Also, we can use function echo in formatting web pages.
<?php
echo "<strong>This is bold text</strong>";
echo "<i>This is italic text</i>";
?>
// in output we get
This is bold text
This is italic text
There is another function for text output print() .
Тhe difference between print() and echo().
- print() has returned value (1)
- we cant use multiple parameters for print()
- print() is processed slower than echo()
<?php
print 'Hello';
//Output a string hello
print $variable;
//Output a value of $variable
?>
0 Comments
CAN FEEDBACK
Emoji