Results 1 to 6 of 6
April 7th, 2008, 11:03 AM #1PHP and Quotes in HTML Tags
What is the best way to handle quotes for attributes in HTML tags. I ask because I am working on a project and it just seems easier to have the entire file coded in PHP and define variable once rather then using PHP tags to do the work in areas of the page.
What triggered the question what the head and metatags. Is is better or ok to include the quotes and escape them with a slash / or can I leave the quotes off the html tags?Thanks,
April 7th, 2008, 11:15 AM #2
I usually backslash the quotes....
$tmp = "some \"quoted\" goes here";
April 7th, 2008, 11:33 AM #3Originally Posted by itsupportnotes
Avoid Double Quotes Around Strings that Contain HTML.
PHP offers a choice between using single or double quotes around strings (as well as perl's "heredoc"). The difference between the two methods is that variables are expanded within double quotes, but not within single quotes.
To avoid variable concatenation, many people get in the habit of using double quotes for strings. But HTML also uses double quotes for attributes, and so lines of code can easily wind up looking like this: Source: PHP Coding Style and Organization
April 7th, 2008, 11:34 AM #4
- Join Date
- October 22nd, 2006
Alternatively you could use a mix of single and double quotes.
$tmp = "some 'quoted' goes here";
April 7th, 2008, 02:35 PM #5
- Join Date
- September 5th, 2005
- Mansfield, TX
As a programmer myself I always thought it best to escape them using thier entity equivalent. For quotes I use "
In otherwords the syntax would be:
$tmp = "some "quoted" goes here";
This works regardless of where the text will be before being displayed in HTML such as a database or XML file.
April 7th, 2008, 03:28 PM #6
The best solution is to keep your HTML files separate from your PHP files. Try not to echo any HTML with your PHP, but rather use a template class like Smarty. This allows you to insert variables into your HTML templates and have your PHP code fill it in.
But if this is too much to handle right now, you should just end your PHP code and do your HTML as you would normally. For example:
<?php php code here.. ?> HTML code here with "normal" quotes. <?php finish your PHP ?>
- ScottHatred stirs up strife, But love covers all transgressions.
By hazlcha in forum WebMerge (Fourthworld.com)Replies: 5Last Post: August 21st, 2014, 06:17 PM
By HumbleFish in forum Programming / Datafeeds / ToolsReplies: 17Last Post: April 15th, 2010, 02:43 AM
By jpiper in forum WebMerge (Fourthworld.com)Replies: 2Last Post: October 13th, 2006, 06:19 PM
By Roland in forum Midnight Cafe'Replies: 1Last Post: July 21st, 2004, 12:38 AM
By Serena in forum Programming / Datafeeds / ToolsReplies: 1Last Post: June 13th, 2004, 07:47 AM