foreach ($author_query as $author) {
echo $author['name'].", ";
}
I am trying to add a href link to it, but I’m having issues with quotes. What’s the right way to do this? The code below doesn’t work because I already opened single quotes with a href, then tried to use it with person_id.
1 .Never ever use \ because it breaks the flow and is confusing
2. always start and end with a single quote
3. add double quotes within the string (ie. width=“123” height=“456”)
4. use .$variable to add to string (throws error if not defined)
5. single quotes within array elements or variable
6. indent wherever possible
edit:
Just checked and noticed @ralphm’s recommendation is the same without indentation.
Remember that the only escapes allowed inside single quotes are to escape single quotes and that everything is considered to be text.
With double quotes the content gets parsed for variable names and additional escapes are allowed - eg. “\n” is the only way to specify a new line character.
Another question, is it okay to store names in the database like below? That way I don’t have to escape but I don’t know whether it’s a good practice or not.
Don’t do that - you should only convert to use HTML escape codes immediately before outputting to HTML. Suppose you decide to output to a PDF ow a word processor instead and now you have garbage in the content.