PDA

View Full Version : HTML entities


dc2000
06-26-2006, 07:25 PM
Hello:


Why when I use the following line:echo "123&222<br>";the output in browser becomes123&amp;222<br>
Why is that? How to avoid conversion from & into &amp;?

I just caught that links that I generate via PHP, say something like this:print "<a href='123.php?id=1&v=123'>";turn into<a href='123.php?id=1&amp;v=123'>

page1ink.
06-27-2006, 07:02 PM
well to get technical, &amp; is the 'proper' way of displaying an amperstand. ever view a web page and see question marks where all the apostrophes should be? that's what happens when you use characters that aren't in the defined Character Encoding set (by default for most people: ISO 8859-1 (http://en.wikipedia.org/wiki/Iso_8859-1) [wiki]). same thing with Japanese pages: unless your browser is told "hey, this page is in japanese and these are all japanese characters," all you'll see is a bunch of funky jibberish.
encoding your 'special' characters with entities prevents this problem: every Character Encoding (http://en.wikipedia.org/wiki/Character_encoding) [wiki] set has a defined &amp; character, whether it's looks like &, +, or even Ò. according to XHTML (http://en.wikipedia.org/wiki/Xhtml) [wiki] standards, you're supposed to encode special characters in URLs as well as in body text. so really &amp; is good stuff!
one more note: you should also use double quotes to surround your tag's attribute values:
print '<a href="somepage.php?a=1&amp;b=2&amp;c=3" title="a, b, c : 1, 2, 3">link</a>';
but regarding your question, that sounds like something your HTML editor is doing. are you using Dreamweaver or Frontpage or anything like that?

dc2000
06-27-2006, 09:49 PM
Thanks for the explanation. I'm using FrontPage. Indeed, the problem was in one argument missing that's why I thought those &amp; symbols were to blame...

page1ink.
06-28-2006, 10:21 PM
glad my spiel could be of help =)