473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

display VARCHAR(mysql) and special chars in html

hello,

my script selects a comment saved as VARCHAR in MySQL and displays it
inside an html page.

the problem is, that the comment contains several special characters, as
mysterious utf-8 hyphens, german umlauts, etc.

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?

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.

bye
jonas
Jul 18 '05 #1
6 2766
Jonas Meurer <jo***@freesources.org> wrote:
hello,

my script selects a comment saved as VARCHAR in MySQL and displays it
inside an html page.

the problem is, that the comment contains several special characters, as
mysterious utf-8 hyphens, german umlauts, etc.

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


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')
--
-----------------------------------------------------------
| Radovan GarabĂ*k http://melkor.dnp.fmph.uniba.sk/~garabik/ |
| __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk |
-----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
Jul 18 '05 #2
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?

bye
jonas
Jul 18 '05 #3
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

Jul 18 '05 #4
Jonas Meurer wrote:
hello,

my script selects a comment saved as VARCHAR in MySQL and displays it
inside an html page.

the problem is, that the comment contains several special characters, as
mysterious utf-8 hyphens, german umlauts, etc.

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?

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.

bye
jonas

If I understand you correctly, just put

<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8">

somewhere in the <head>-section of you HTML-Page.

HTH,
Wolfram
Jul 18 '05 #5
Wolfram Kraus <kr***@hagen-partner.de> wrote:
Jonas Meurer wrote:
hello,

my script selects a comment saved as VARCHAR in MySQL and displays it
inside an html page.

the problem is, that the comment contains several special characters, as
mysterious utf-8 hyphens, german umlauts, etc.

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?

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.

bye
jonas

If I understand you correctly, just put

<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8">

somewhere in the <head>-section of you HTML-Page.


.... and make sure the deault charset of your HTTP server is *OFF* (or
UTF-8), since it overrides the per-page setting (most unfortunate).

--
-----------------------------------------------------------
| Radovan GarabĂ*k http://melkor.dnp.fmph.uniba.sk/~garabik/ |
| __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk |
-----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
Jul 18 '05 #6
Jonas Meurer wrote:
(...)
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?


as you may known mysql 4.1 offers utf-8 support. il would be
wise to keep everything as utf-8: db, html generation and finally
serve, with correct HTTP headers, pages encoded as utf-8.

to do this you might have to fiddle with mysql settings and make
sure that issuing a:

show varibles;

almost all of these settings:

character_set_client latin1
character_set_connection latin1

character_set_database latin1

character_set_results latin1
character_set_server latin1
character_set_system utf8
use utf-8 (as you can see my copy of mysql does not), otherwise i
think bad things will occur.

if you prefer to filter out weird characters and
encode as html &#xxxx entities textile[1] does the job
just fine, you can specify input and output encoding.

cheers,
deelan.

[1] http://dealmeida.net/en/Projects/PyTextile/

--
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog <http://blog.deelan.com/> .
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Adam Kenney | last post by:
Is there a control for Windows Forms that will display HTML (from either a variable or a stored file) as it would appear in a browser window? I'm trying to create a Windows Form that includes a...
0
by: dragan | last post by:
I want to display HTML file as an embedded resource, (read it into MS webBrowser control.) I also have pictures in HTML file. My problem is that I dont want users to be able to copy text in...
1
by: GM | last post by:
how can I display on a page or textfield html text and formating stored in a database field? thanks,
3
by: GM | last post by:
Is it possible to display html stored in a database field into a textarea? How can you display the html and allow editing? thanks,
1
by: Robert | last post by:
Display html pages within an aspx page I would like to display HTML pages within an aspx page.An example might be: I have an aspx page with a menu on the left side and by clicking on one of the...
1
by: The Colonel | last post by:
I have a database of our company's HTML email templates - name, subject, etc. Well, some are for HTML emails, and the template_text column contains HTML. When I display in a datagrid, it REALLY...
10
by: Stephen M. Gava | last post by:
Hi all, I prefer using tkinter to wxpython (so sue me :) and i need to display a lot of html in a particular app. does anyone know if one of the existing add on tk html widgets have been wrapped...
4
by: ArrK | last post by:
I want to use a control frame to create and/or modify the content (images and text) of a display frame - all files and images are client side. . When I try to write to the display frame from the...
1
by: pyssarma | last post by:
hi, I am new to mysql (4.0) php combination. Trying to display mysql table data using php. I have tested connection successfully but could not display table data using php. What could be the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.