开发者

W3C Validation and code in website text

If I were to take the error logs of a file, and put them on a properly formatted HTML page, the page might not pass validation by W3C's validation tool because the error text contains markup that the validation tool gets confused with. How can I properly mark such text such that the validation tool realizes that 开发者_如何学编程it's reading what should be interpreted as a normal string and not markup?


You need to convert the following characters into their HTML entities (stolen from the PHP manual on htmlspecialchars()):

'&' (ampersand) becomes '&'
'"' (double quote) becomes '"' 
''' (single quote) becomes ''' 
'<' (less than) becomes '&lt;'
'>' (greater than) becomes '&gt;'


If it really is a normal string, then you should represent the characters that have special meaning in HTML with their respective entities. < to &lt; etc.

This will, of course, cause browsers to render those characters as text and not tags.

If you want browsers to render them as tags, then they aren't a normal string and they are a validity error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜