replace & for &
I'm trying to validate using W3C validation system and i get an error:
Line 59, Column 47: character "&" is the first character of a delimiter but occurred as data
I know the reason why:
You used an unescaped amp开发者_StackOverflow社区ersand "&": this may be valid in some contexts, but it is recommended to use "&", which is always safe.
In the form, i've entered it like this
SONY & BMG MUSIC ENTERTAINMENT
If i go in phpadmin, in the table, i can see the data correctly
SONY & BMG MUSIC ENTERTAINMENT
Does it mean that i have to enter it using "&" ... this is crazy, what if i have a text... do i have to replace every & for "&"
I'm sure there's is a better way to do this.. any hints or ideas?
Thanks
You should only escape your data for HTML when you use it in the context of HTML.
Use htmlspecialchars()
when you output your data. For example:
$title="SONY & BMG MUSIC ENTERTAINMENT";
echo htmlspecialchars($title);
It is best practice to leave the data plain in the database, as you may want to use it in a completely different context for something else in the future. That is, don't escape your data prior to inserting into the database. Only worry about it when you output it.
精彩评论