Solved

Display special characters from database

Posted on 2009-04-09
6
682 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

734 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