tags:

views:

100

answers:

4

Basically, i would like to echo out something along the lines of <p style="color:FFFFFF">, or possibly a class, but it seems the parser isn't really liking the fact that it contains quotes, and it quickly destroys my site. Is there any hack to get around the parser rules, alternatively a better solution?

Cheers.

+7  A: 
echo '<p style="color:#000;">test</p>';

or

echo "<p style=\"color:#000;\">test</p>';

and a couple other combinations are possible. The point is that you should take into account what quotes you're using to spit out the entire string, and which quotes are used in the HTML. If you need to use the same ones, " and " you have to escape the inner " or the parser will think that denotes the end of the string.

meder
Thanks! I'm rather new to PHP, i suppose that shows, but i'm really glad you guys are happy to help :)
Andreas Carlbom
+1  A: 

Simply escape your quotes:

echo "<p style=\"color:FFFFFF\">";
Malax
+1  A: 

You could also

echo "<p style='color:#FFFFFF'>";
pavium
It should be noted that the single-quote in attributes is considered invalid in XHTML. Using double quotes also keeps you consistent with any XML you may use which is also very prevalent in web development nowadays.
Paulo
Thanks Paulo, the subject of validation is important and it was probably a personal preference for single quotes inside double quotes. In future, I'll stick to double *inside* single. If the echo needs double quotes I'll have to escape the interior quotes.
pavium
A: 

or perhaps:

echo '<p style="color:#fff">test</p>';

jerjer