Jump to content

MySQL, PHP, Smarty, Apache and East Asian Characters


Navarr

Recommended Posts

Well, this has to be the worst problem I've ever had with MySQL, PHP, Smarty, and Apache.

 

MySQL isn't having the problem.  Using phpMyAdmin, I can put Japanese into the database, and phpMyAdmin will echo it back out as Japanese.  But, when my website tries to set it to a variable after grabbing it from MySQL, and then displays it with Smarty, all I get are question marks! @.@

 

A good example of whats happening is at http://tempdev.pkqst.com/changelang.php?lang=JP (Any browser thats not IE should work, the script changes a cookie to make the language japanese before redirecting you to the homepage).  As is visible there, Language Variables set in a PHP Script and are called as a variable by smarty show up fine, but when its grabbed from MySQL, it and stored to a Smarty variable and attempts display, it doesn't work.  Can anyone help with this?

Sorry to double post, but there is no edit feature that I could find.

This is the code:

 

index.php

<?php
        require('inc.php');
        $tpl->assign('page','news');
        $browser = (array)get_browser();
        $tpl->assign('browser',$browser['browser']);
        $forum = 1;
        if ($language == 'en-US') { $forum = 1; }
        if ($language == 'JP') { $forum = 2; }
        $news = array();
        $q = mysql_query("SELECT * FROM `xt_bbs_posts` WHERE `parent` IS NULL AND `forum`=".$forum." ORDER BY `time` DESC LIMIT 0,10") or die(mysql_error());
        while($r = mysql_fetch_array($q)) {
                $i = count($news);
                $news[$i]['ico'] = '';
                $news[$i]['icoalt'] = '';
                $news[$i]['title'] = $r['title'];
                $news[$i]['time'] = lang_time($language,$r['time']);
                $news[$i]['date'] = lang_date($language,$r['time']);
                $news[$i]['post'] = $r['post'];
                $news[$i]['poster'] = $r['uid'];
                $news[$i]['commamt'] = 0;
        }
        $tpl->assign('news',$news);
        $tpl->display('index.tpl');
?>

 

index.tpl

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg-flat.dtd">
<html xmlns             = "http://www.w3.org/1999/xhtml" xml:lang="en-US"
      xmlns:svg         = "http://www.w3.org/2000/svg"
      xmlns:xlink       = "http://www.w3.org/1999/xlink">
<head>
  <title>{$lang.title}{$title}</title>
  <link rel="stylesheet" type="text/css" href="/style.css" />
</head>
<body>{strip}
  <div id="logodiv"><h1 style="visibility:hidden;">POKéQUEST - Pokémon Online Game - Pokemon Online Game - Pokemon MMO - Pokémon MMO - Pokemon MMORPG - Pokémon MMORPG</h1></div>
  <div id="navidiv">
   {include file="navi.tpl"}
  </div>
  <div id="maindiv">
   {if $browser == "IE"}
   <div id="iewarning">THIS PAGE DOES NOT WORK PROPERLY IN IE, PLEASE GET <a href="http://opera.com/">OPERA</a> OR <a href="http://getfirefox.com">FIREFOX</a></div>
   {/if}
   {include file="$page.tpl"}
  </div>
{/strip}</body>
</html>

 

news.tpl

{strip}{section name=i loop=$news}
<table class="news_table">
  <tr>
   <th class="news_table_topic"><img src="{$news[i].ico}" alt="{$news[i].icoalt}" title="{$news[i].icoalt}" /> {$news[i].title}</th>
   <td class="news_table_time">{$news[i].date}<br />{$news[i].time}</td>
  </tr>
  <tr>
   <td class="news_table_post" colspan="2">{$news[i].post}</td>
  </tr>
  <tr>
   <td class="news_table_poster"><a href="{$news[i].posterurl}">{$news[i].poster}</a></td>
   <td class="news_table_comment"><a href="{$news[i].commurl}">{$news[i].commamt} {if $news[i].commamt == 0}Comments{/if}{if $news[i].commamt > 1}Comments{/if}{if $news[i].commamt == 1}Comment{/if}</a></td>
  </tr>
</table>
<br />
{/section}{/strip}

The problem seems to be when my PHP script grabs the information from MySQL.  I can't figure out how phpMyAdmin manages to grab it properly, but it does.  If anyone could help make some pointers to what the problem is, I would greatly appreciate it.. Nobody has yet, and I'd really like some help here.  Its not that the page isn't encoded properlly, its sending header('Content-Type: text/html;charset=utf-8');  So the error is somewhere in the PHP.  If anybody could help, that would be wonderful wonderful.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.