PHP String
PHP String
Single Quoted
We can create a string in PHP by enclosing the text in a single-quote.
It is the easiest way to specify string in PHP.
For specifying a literal single quote, escape it with a backslash (\) and
to specify a literal backslash (\) use double backslash (\\). All the
other instances with backslash such as \r or \n, will be output same
as they specified instead of having any special meaning.
Example
<?php
$str='Hello text within single quote';
echo $str;
?>
Output
Hello text within single quote
We can store multiple line text, special characters, and escape
sequences in a single-quoted PHP string.
Double Quoted
In PHP, we can specify string through enclosing text within double
quote also. But escape sequences and variables will be interpreted
using double quote PHP strings.
Example
<?php
$str="Hello text within double quote."
echo $str;
?>
Output
Hello text within double quote.
Now, you can't use double quote directly inside double quoted
string.