PHP echo() Function
In this chapter you will learn:
- Definition for PHP echo() Function
- Syntax for PHP echo() Function
- Parameter for PHP echo() Function
- Return for PHP echo() Function
- Example - Write some text to the output
- Example - Write the value of the string variable ($str) to the output
- Example - Join two string variables together
- Example - Write the value of an array to the output
Definition
The echo() function outputs one or more strings.
The echo() function is not a function, so parentheses are not required.
Syntax
PHP echo() function has the folloiwng syntax.
echo strings;
Parameter
Parameter | Is Required | Description |
---|---|---|
strings | Required. | One or more strings to be sent to the output |
Return
No value is returned
Example 1
Write some text to the output:
<?php
echo "Hello world!";
?>
The code above generates the following result.
Example 2
Write the value of the string variable ($str) to the output:
<?php
$str = "Hello world!";
echo $str;
?>
The code above generates the following result.
Example 3
Join two string variables together
<?php/*from ja va 2 s . co m*/
$str1="Hello world!";
$str2=" from java2s.com!";
echo $str1 . " " . $str2;
?>
The code above generates the following result.
Example 4
Write the value of an array to the output
<?php
$age=array("PHP"=>"5");
echo "PHP is " . $age['PHP'] . " years old.";
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP get_html_translation_table() Function
- Syntax for PHP get_html_translation_table() Function
- Parameter for PHP get_html_translation_table() Function
- Return for PHP get_html_translation_table() Function
- Example - Print the translation table used by the htmlspecialchars function
- Example - Table for HTML_SPECIALCHARS
- Example - Table for HTML_ENTITIES
Home » PHP Tutorial » PHP String Functions