A sequence of characters is called as string. In PHP, a string can be specified in four ways:
- single quoted string
- double quoted string
- heredoc syntax string
- newdoc syntax string
Single Quoted String:
A string enclosed in a single quote is called a single quoted string. Escape sequences and variables can not be interpreted using single quoted strings.
Double Quoted String:
A string enclosed in a double quote is called a double quoted string. Escape sequences and variables can be interpreted using double quoted strings.
Example 1: Variables inside a Single quoted string
<!DOCTYPE html> <html> <body> <?php $num=100; $string='print $num'; echo "$string <br/>"; ?> </body> </html> |
Output
print $num |
Example 2: Variables inside a Double quoted string
<!DOCTYPE html> <html> <body> <?php $num=100; $string="print $num"; echo "$string <br/>"; ?> </body> </html> |
Output
print 100 |