简体   繁体   中英

Displaying Special Characters from MySQL Database in Joomla

I am trying to save text and then display text from MySQL Database in Joomla.

I created a PHP file to save text via post.

$text = $_POST['text'];
$text = mysql_real_escape_string($text);
mysql_query("INSERT INTO question(`question`) VALUE('$text')");

The text i copied from word had a special character.

The line copied was:

Total age = 20 × 9 = 180 years

In the database table (charset=utf8 COLLATE=utf8_unicode_ci), the text is saved as

Total age = 20 × 9 = 180 years

Now if i fetch this text in a PHP and in that PHP i add this line:

<meta charset="UTF-8">

Then the text is displayed correctly.

If i fetch the same text in a Joomla Website, which already has utf-8 meta (checked in source code), the text is not displayed correctly. It always shows:

Total age = 20 × 9 = 180 years

I have tried adding these:

mysql_set_charset('utf8');
ini_set('default_charset', 'UTF-8');
header('Content-Type: text/html; charset=utf-8');
mysql_query("SET NAMES 'utf8'");
utf8_encode($text);

But i could not decode the characters inside Joomla. Please help.

Try the following:

  • Use utf8_general_ci as encoding for all your tables
  • Use utf8_general_ci as encoding for your database

You can make these changes in phpMyAdmin (I think there is a query to change the character encoding for all the tables)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM