Saturday, March 8, 2014

Difference between single quotes and double quotes in string.(PHP)

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.

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