Single and double quotation marks work in different ways.
If you enclose a string in single quotation marks, PHP uses the string exactly as typed.
However, double quotation marks has extra features:
variable names within the string are parsed and replaced with the variable's value special characters need escaping in the string.
<?PHP
$str = 'world';
echo "Hello, $str! \n"; // Displays "Hello, world!"
echo 'Hello, $str! \n'; // Displays "Hello, $str!"
echo " Hi\tFriend! "; // Displays "Hi Friend!"
echo ' Hi\tFriend! '; // Displays "Hi\tFriend!"
?>
If you enclose a string in single quotation marks, PHP uses the string exactly as typed.
However, double quotation marks has extra features:
variable names within the string are parsed and replaced with the variable's value special characters need escaping in the string.
Example:
<?PHP
$str = 'world';
echo "Hello, $str! \n"; // Displays "Hello, world!"
echo 'Hello, $str! \n'; // Displays "Hello, $str!"
echo " Hi\tFriend! "; // Displays "Hi Friend!"
echo ' Hi\tFriend! '; // Displays "Hi\tFriend!"
?>
No comments:
Post a Comment