Write a program to print a string using echo+variable.
Description: Write a PHP program to print “Welcome to the PHP World”. Keep a part of the text in a variable, and write the other part directly in echo.
Rules and hints:
- Use a variable that contains the string “PHP World”.
- Join the variable with the rest of the text using the dot (
.) operator.
PHP program to print a text using echo and a variable
<?php
$world = "PHP World";
echo "Welcome to the " . $world;
?>
Output:
Tutorials Class - Output Window
Welcome to the PHP World
How it works
- The dot operator joins the text with the variable.
- You can also write
echo "Welcome to the $world";. Variables inside double quotes are replaced by their values.
Related: How to concatenate two strings in PHP.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Variables |
| PHP Data Types |
| PHP Constants |
| PHP isset() Function |
| PHP empty() Function |
| PHP is_null() Function |
| Exercises & Assignments |
|---|
| Write a program to print “Hello PHP” using variable |
| Write a program to print a string using echo+variable. |
| Write a program to print two variables in single echo |