Reputation: 839
I use sprintf()
on my program to output some tabs and newlines. I noticed a part of my program not working properly.
As I inspected the part that isn't working, I noticed that I used a single quote '
instead of a doublequote "
and the program actually outputs a \t
instead of a inivisible tab space.
I thought the two are similar and the reason for having two delimeters for php is for us to be able to insert single or doublequote in a string or echo
them without inserting escape characters.
Would there be a difference in assigning variables aside from the one I discovered
$a = "qq";
$b = 'qq';
Would they be stored in the computer's memory in a different manner?
Upvotes: 0
Views: 3346
Reputation: 2256
Upvotes: 1
Reputation: 2103
if you use single quotes for the format string (like you should do, since there
aren't any variable conversions to do as long as you don't need any special chars),
the given examples won't work because of the backslash before the $ (needs to be
escaped in double quoted strings - but not in single quoted!) http://php.net/manual/en/function.sprintf.php
Upvotes: 0
Reputation: 689
you can refer to the manual that specifies that single quotes in php consider most escape sequences as litterals, contrary ot double quotes: http://php.net/manual/en/language.types.string.php
Upvotes: 1