The primary difference between putting single quotes and double quotes around a string value is how the PHP interpreter deals with what's inside.
If it's enclosed in single quotes, it's treated as a literal string and no more.
If it's enclosed in double quotes, then any variables inside the string get parsed and replaced.
Examples:
PHP Code:
$color = 'blue';
$img = '<img src="images/$color.jpg" />';
echo $img;
Output:
HTML Code:
<img src="images/$color.jpg" />
PHP Code:
$color = 'blue';
$img = "<img src=\"images/$color.jpg\" />";
echo $img;
Output:
HTML Code:
<img src="images/blue.jpg" />
But I think concatenating the literal strings with variables is easier to read and less prone to human error:
PHP Code:
$color = 'blue';
$img = '<img src="images/' . $color . '.jpg" />';
echo $color;
Output:
HTML Code:
<img src="images/blue.jpg" />
Bookmarks