Solved

Display special characters from database

Posted on 2009-04-09
6
677 Views
Last Modified: 2014-05-11
Hello,
I have a simple php page that allows a user to update database data.  The data is then displayed on a webpage (VERY simple content admin).

Occasionaly, special characters like bullets, and trademarks are used in these updates.

IDEALLY I would like to be able to just copy and paste text with these characters in the php form that updates the database, but when I do this, I get "unknown character icons" on the display page.

Using special character codes would be okay (not optimum), but the problem I am running into is when I use the codes ("•" for example), they show up fine on the display webpage the first time, but if I go back and use the php form to make a change, the character codes show up as the characters they represent in the form field and when I update the database, the "unknown character icons" are displayed on the page again, thus creating a situation where I have to convert the characters to their code counterparts everytime I edit the page.

How can I get the display page to display the special characters, or, short of that, retain the character codes when I edit the data in my php form?

Thanks in adavance.
0
Comment
Question by:tmbdesign
6 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 336 total points
ID: 24112489
This can be very tricky, one approach to learn the character encoding is to go to View->Encoding and to try different character encoding schemas to see which one displays the characters properly, then add a meta tag identifying this schema, e.g.:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

PHP also offers you character encoding conversion functions such as http://us2.php.net/iconv that allow you to convert from one encoding schema to another.
0
 

Assisted Solution

by:kevintynfron
kevintynfron earned 168 total points
ID: 24121127
I'm not sure from your description exactly what you're seeing, but I had problems with this kind of thing as well.

I had my database character set as UTF-8 and the web page using UTF-8 as shown above, but I was still having problems editing it as the characters weren't showing up properly in the edit box.

In the end, I used the htmlspecialchars function to populate the text box in my PHP.
<input value="<?php echo htmlspecialchars($row_member_details['surname']); ?>" type="text" name="member_surname" id="member_surname" />

Open in new window

0
 
LVL 19

Assisted Solution

by:LordOfPorts
LordOfPorts earned 336 total points
ID: 24123301
One other important fact is which character encoding your database uses, when you connect to you MySQL database try issuing the following command before you query the database:
mysql_query("SET NAMES 'utf8'");

Open in new window

0
 

Author Comment

by:tmbdesign
ID: 24354818
Hey Everybody,
I am so sorry to have abandoned this question.  I got way busy with other things and couldn't find time to follow through with the suggestions.

I still hope to get back to this project at some point, but in the mean time, I agree with the split.

Thanks.
0
 
LVL 2

Expert Comment

by:ref-IT
ID: 40057266
Hello Boys,

I'm aware that this post has long since been closed, but I'd like to mention that LordOfPorts's solution of changing MySQL Database's characters set using

mysql_query("SET NAMES 'utf8'");

before querying the database actually worked for me.

Thanks a lot and God Bless.

ref-IT
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now