Jump to content

Wrapping '%' In Quotes?


Recommended Posts

That's not a good topic title, I apologize.


I've always thought that when defining width or height or anything else that anything BUT an absolute number should be wrapped in double quotes.

Like width=950 OR width="!00%" . I need to define "100%", "top", "center", etc but of course php says "no, No, NO!"

So I have tried:

echo "<table width=100% align=center border=0 cellpadding=5 cellspacing=1>\n<tr valign=top align=center>\n";


That works but is it correct? I wonder if that should all be in 'single' quotes (also works)


echo "<table width='100%' align='center' border=0 cellpadding=5 cellspacing=1>\n<tr valign='top' align='center'>\n";




Happy New Year! :)

Link to comment
Share on other sites

  • 1 month later...

Or of course just escape the quotes like \"


echo "<table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"1\">\n<tr valign=\"top\" align=\"center\">\n";


But my personal preference is to always use single quotes when possible for PHP strings since it gives a slight speed boost compared to double quotes. This is because PHP scans double quotes strings for variables and special characters (like \n) but with single quotes it only looks for \'. Whilst the speed difference with a single string is negligible imagine outputting a whole scripts worth. This is why Bob's method is preferable.


Oh and always wrap your html attributes in double quotes. That is the standard.

Edited by carbonize
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...