The string variables can contain alphanumeric characters.
Strings in PHP are declared in two ways:
Single quoted (‘ ‘)
Double quoted (“ “)
php script Syntax :
If you define the string in single quotes, the content will be displayed in output browser without any changes.
If you define the string in double quotes, the content will be interpreted and the output of the program will be displayed.
Sample Code :
Code Explanation :
Here in this statement we define the variable “$Ten” and assign the value as “10”.
In this Example, the “$var1” is a variable starts with the “$” sign with their variable name. In this example the variable holds the string value in single quotes (‘ ‘).
“$var2” is a variable name that’s holds the string value using double quotes (“ “) .
echo $var1 – is the echo statement displaying the value of the variable by displaying in the browser without any changes because we defined the ‘var1’ in single quotes.
echo $var2 – is the echo statement that displays the value of the variable by interpreting (by changing) the output & displaying in the browser.
Sample Output :
Here in this output the statement “Wikitechy is the Top $Ten Technical Website” has be declared in the variable “var1” in single quotes so the output will be displayed without interpreted.
Similarly, the statement “Wikitechy is the Top 10 Technical Website” has be declared in the variable “var2” in double quotes so the output will be displayed after the interpretation of the variable “$Ten” whose value “10” has been assigned here.