Blog : PHP echo() Function
PHP echo() Function
--------------------------------------------------------------------------------
Complete PHP String Reference
--------------------------------------------------------------------------------
Definition and Usage
The echo() function outputs one or more strings.
Syntax
echo(strings)
Parameter Description
strings Required. One or more strings to be sent to the output
--------------------------------------------------------------------------------
Tips and Notes
Note: The echo() function is not actually a function, so you are not required to use parentheses with it. However, if you want to pass more than one parameter to echo(), using parentheses will generate a parse error.
Tip: The echo() function is slightly faster than print().
Tip: The echo() function has the following shortcut syntax. See example 5.
--------------------------------------------------------------------------------
Example 1
$str = "Who's Kai Jim?";
echo $str;
echo "
";
echo $str."
I don't know!";
?>
The output of the code above will be:
Who's Kai Jim?
Who's Kai Jim?
I don't know!
--------------------------------------------------------------------------------
Example 2
echo "This text
spans multiple
lines.";
?>
The output of the code above will be:
This text spans multiple lines.
--------------------------------------------------------------------------------
Example 3
echo 'This ','string ','was ','made ','with multiple parameters';
?>
The output of the code above will be:
This string was made with multiple parameters
--------------------------------------------------------------------------------
Example 4
Difference of single and double quotes. Single quotes will print the variable name, not the value:
$color = "red";
echo "Roses are $color";
echo "
";
echo 'Roses are $color';
?>
The output of the code above will be:
Roses are red
Roses are $color
--------------------------------------------------------------------------------
Example 5
Shortcut syntax:
$color = "red";
?>
Roses are