I am getting a lot of errors lately on a Joomla project and have found things like (in class code)…
return "<span class='...
or
echo "<h3 id='...
instead of
return "<span class=\"...
echo "<h3 id=\"...
This includes many times a variable in quotes, but it still finds it’s way to my browser with single quotes. Before going through and changing these, I wanted to see what others have to say. My project is at http://dev.thediabetesnetwork.com.
I have looked this up and find a lot of conflicting information, so figured I would revive the discussion for the newest PHP/browser configurations and see if I am overlooking other details.
It’s a lot easier to read without all the double quotes inside the string being escaped with
\.If you need to output a variable inside a string expression, double quotes must be used. If you are outputting HTML inside double-quotes, you can either use
'or\"to enclose HTML attributes. The first is preferred because it results in cleaner PHP code.If you don’t want your HTML to use single quotes, then you can just escape all of your quotes, use heredoc syntax, or concatenate your variables into the string like: