Characterset conversion


#1

Hi group,
I have a simple web-app that reads files and stores them in MySQL. Now I
noticed that some characters are converted so some characterset
conversion must be taking place. For example the character - is
converted in â??.

From phpinfo:
HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,;q=0.7
HTTP Headers Information = Accept-Charset ISO-8859-1,utf-8;q=0.7,
;q=0.7

I have tried adding the following to my virtualhost: AddDefaultCharset
utf-8
But that did not help. I suspect the problem is not the webserver-config
as the web-app is just reading a file from the local filesystem and
storing it in mysql. Maybe this is caused by my windows settings?

The MySQL table column is of type longtext and utf8 characterset, the
same as the html documents.

I’m using ruby 182-15.

Any ideas on how to fix this will be greatly appreciated.
Onno

This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by, any other party. If you are
not an intended recipient then please promptly delete this e-mail and
any attachment and all copies and inform the sender. Thank you.


#2

Straaten, Onno van der wrote:

The MySQL table column is of type longtext and utf8 characterset, the same as the html documents.

This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

You could try something like I do in my AJAX UTF-8 to ANSI
convertion…

require ‘iconv’

def auto_complete_for_movie_movie_id
da_title = Iconv.new(‘iso-8859-15’,
‘utf-8’).iconv(params[:movie][:movie_id])
auto_complete_responder_for_movies da_title
end

(I know it looks strange to have movie_id as a "movie title" and not the id from the DB, but I must handle Titles that do not yet exists)

In your case:
safe_text = Iconv.new( ‘utf-8’,‘iso-8859-1’,).iconv(some_text_from_file)

More on “iconv” on http://wiki.rubyonrails.com/rails/pages/iconv

Regards
Jonas Montonen,

http://bytadvd.se - DVD Swapping site in Swedish