Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- what is wrong with this code?
February 28, 2005, 10:53 pm
rate this thread
I was under the impression that the single quote ' did not interpret
this gives as expected "a"
I want "<a" but
it gives "<a>
So without the closing " but with a closing >
Strange. What am I doing wrong?
Re: what is wrong with this code?
No, that isn't the output. The output is exactly what you
thought it should be; that is, "<a".
However, browsers understand '<' to be the start of a tag if
it is followed by a Name Start Character. A browser would
then read the 'a' but get confused when it comes across '"',
which isn't a valid Name character in HTML. It looks as
though error recovery kicked in and everything up until the
'>' of '</BODY>' was ignored. Thus, you were presented with
"<a> by your web browser.
When '<' comes immediately before a Name Start Character,
such as 'a', it needs to be encoded, either with <, <
or <, if it is to be taken literally. The
htmlspecialchars function converts '<' to <.