In this PHP tutorial, you shall learn how to create a new string using single or double quotes notation, with example programs.
PHP – Create a String
To create a string literal in PHP, we can either enclose the string value in single quotes, or double quotes.
The following is a simple example to create a string literal using single quotes.
'Hello World'
The following is a simple example to create a string literal using double quotes.
"Hello World"
Examples
1. Create string using single quotes
In the following program, we create a string using single quotes, assign it to a variable named str
, and print it using echo.
PHP Program
<?php
$str = 'Hello World';
echo $str;
?>
Output
2. Create string using double quotes
In the following program, we create a string using double quotes, assign it to a variable named str
, and print it using echo.
PHP Program
<?php
$str = "Hello World";
echo $str;
?>
Output
Conclusion
In this PHP Tutorial, we learned how to create a string literal using single or double quotes, with examples.