Solved

Display special characters from database

Posted on 2009-04-09
6
680 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

825 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