0

Here's the situation: I have a dictionary database. I use special characters in the pronunciation (like this: 'hə.lə.ba.lu). However, when I use a PHP script to output this data, the special characters get replaced with question marks. Like this: 'h?.l?.ba.lu

I've read a lot on this topic, but I'm not sure where to start or what to check.

Here's some information:

The collation of my database is utf8_general_ci
The collation of the tables is utf8_general_ci
The character set of the page is UTF-8

I've also seen some references to htmlentities, but I'm not sure how to incorporate the code into my code.

Here is the PHP code that I'm using for the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Newsletter Tests</title>
<style type="text/css">
#IPA
.IPA {
font-family:Arial Unicode MS,Code2000,Gentium,GentiumAlt,DejaVu Sans,Segoe UI,Lucida Grande,Charis SIL,Doulos SIL,TITUS Cyberbit Basic,Lucida Sans Unicode,sans-serif;
font-size:110%;
}
</style>
</head>
<body>
<form name="word" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"><fieldset>
<legend>Type your word here:</legend>
  <input type="text" name="enteredWord" id="wotd" size="77"> <input type="submit" name="Submit" value="Submit" id="submitwotd">
</fieldset>
</form><br />You entered: <strong><? echo $_POST['enteredWord'] ?><br /><br /></strong>

<?PHP
//Log in to database
$username="myusername";
$password="mypassword";
$database="mydatabase";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

//declare the variable POSTED from the form
$enteredWord = $_POST['enteredWord'];

//if $enteredWord is not blank then proceed.
if ($enteredWord != '') {

$query="SELECT * FROM Dictionary WHERE word='$enteredWord'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
  while ($i < $num) {

  $Word=mysql_result($result,$i,"Word");
  $Definition=mysql_result($result,$i,"Definition");

  echo "<strong>$Word:</strong> $Definition<br />";

$i++;
  }

Thanks for any pointers!

2
Contributors
3
Replies
8
Views
7 Years
Discussion Span
Last Post by Sucesso
0

try some different charset for HTML.

<meta http-equiv="Content-Type" content="text/html; charset=ISO 8859-1" />
0

Thanks for the suggestion. I tried that, but it didn't work--same problem. I get question marks again.

0

Posting in case it helps anyone:

I think I figured it out. First, my problem was that I was copying and pasting special characters into PHPMyAdmin. I decided to try decoding the special characters first. So ə became &#601;. After I did that, I used this code:

<? echo htmlspecialchars($my_db_field, ENT_QUOTES, "UTF-8", false); ?>

to generate the output the way I wanted.

Now, I just need to figure out how to convert all the special characters to decoded HTML.

What a beginner I am... :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.