String containing "<" ">" pulled from db get hidden in html

Associate
Joined
19 Jun 2006
Posts
162
Location
Swansea, Wales
Some of my text fields in the database are "<sometext>". The caveats are important and cant be omitted.

Obviously when they appear in the html they are parsed as html tags and not shown. Aside from scanning each string as it is got from the database and inserted a escape sequence, is there a way to prevent this? Scanning every string is going to be massive overhead!
 
You're going to have to encode the angle brackets as &gt; + &lt; otherwise they will be parsed as html.

Can't the data be filtered before it is entered in the database if it is going to be rendered as HTML? If the data in the database is user supplied then it should definatly be filtered otherwise someone could inject whatever they want into the output.
 
Don't parse it before you enter into the db, parse it just before you display it. This will prevent you seeing the special chars when not using html..
 
Dj_Jestar said:
Don't parse it before you enter into the db, parse it just before you display it. This will prevent you seeing the special chars when not using html..
What he said.
 
Back
Top Bottom