One of the most basic elements of PHP is the ability to save strings as variables and print them. A string is a sequence of characters, commonly used for text elements.
The Code
At this moment, we have saved the string “Hello, World!” as the variable $string. We can now use this variable to display the string anywhere we need to!
Variables
Variables start with the symbol “$”, and are usually followed by the equal sign “=” when setting up a value. The statements must always be closed by a semi-colon “;”.
Variables can be Integers, Doubles, Booleans, NULL, Strings, Arrays, Objects, and Resources.
Print the variable
For this example we will use the print function. It is very easy to use and apply for simple strings.
Complete Code
Create a file called hello.php with the following code and open it on your browser.
Hello, World! Page