display VARCHAR(mysql) and special chars in html

Steve Holden steve at holdenweb.com
Tue Feb 22 17:19:15 EST 2005


Jonas Meurer wrote:

> On 22/02/2005 Radovan Garabik wrote:
> 
>>>i could write a function to parse the comment and substitute special
>>>chars with the relevant html code, but maybe this already exists in some
>>>module?
>>
>>just make the page in utf-8, and you'll save you a lot of troubles
> 
> 
> ok, how do i do this? simply add a second line with this:?
> # -*- encoding: utf-8 -*-
> 
> i use utf8 locales on my machine anyway.
> 
> 
>>>if not, it'll be hard work, as i've to consider many special chars, and
>>>at least iso-8859-1* and utf-8 as charmaps.
>>
>>if you insist...
>>a = u'\u010c'
>>a.encode('ascii', 'xmlcharrefreplace')
> 
> 
> this fails as the comment contained several chars that couldn't be
> converted.
> 
> i've changed my plans, and now will transform the comments to html
> before saving them in mysql. this way, the comment never contains
> special chars except they weren't filtered out when safed in mysql.
> 
> do any filters exist, to transform plain text to html? otherwise i might
> use third-party products, as text2html.
> 
> what do you think?
> 
I think you should store your data with a known encoding, then encode it 
as necessary for transmission. That way you can provide it in the forms 
most relevant to different clients.

regards
  Steve




More information about the Python-list mailing list