...

View Full Version : Resolved Can't get text to encode properly -- MySQL



Cactuar
06-30-2011, 10:11 AM
Forgive me if this is overly basic, but I'm very new to PHP/ MySQL and I haven't been able to find a solution to this.

I have a bilingual site, and wanted to have an RSS feed in each language. I've written a script in PHP that reads information out of the MySQL database, and writes two xml files. The script works fine and the English Language RSS is perfectly readable, but the Japanese language RSS doesn't display properly (link) (http://www.harerudeshou.com/reach/RSS_ni.xml)

Both RSS feeds return "Your feed appears to be encoded as "UTF-8", but your server is reporting "US-ASCII"" when put through the feed validator.


The title, which is written into the PHP, shows up, but the item, which is pulled from the database, does not. The database itself is in utf8_unicode_ci, and I've tried various things with the PHP, and I have also tried creating and uploading a .htaccess file with the following:

AddDefaultCharset UTF-8

<FilesMatch "\.(htm|html|css|js)$">
AddDefaultCharset UTF-8
</FilesMatch>

...but to no avail.

Help?

The relevant portion:


switch($filename) {
case 'RSS_ei.xml':
// snip!
break;
case 'RSS_ni.xml':
fwrite($rssf, pack('CCC',0xef,0xbb,0xbf));
fwrite($rssf, "<?xml version=\"1.0\"?>\n");
fwrite($rssf, "<rss version=\"2.0\">\n");
fwrite($rssf, "<channel>\n");
fwrite($rssf, "<title>ハレル英語</title>\n");
fwrite($rssf, "<link>http://www.harerudeshou.com</link>\n");
fwrite($rssf, "<description>英語教室のための教材やゲーム</description>\n");
fwrite($rssf, "\n");
break;
}

include('figs.php');
?><br><?php
$pass = $_POST['password'];
$connect = mysql_connect($host, $user, $pass) or die("Unable to connect");


mysql_select_db($db) or die("Unable to select database");
//unicode query
$unicode = "SET NAMES 'utf8' COLLATE 'utf8_unicode_ci";
mysql_query($unicode);
//branch for language, create query based on filename
switch($filename) {
case 'RSS_ei.xml':
$querymethis = "SELECT * FROM RSS_ei";
break;
case 'RSS_ni.xml':
$querymethis = "SELECT * FROM RSS_ni";
break;
}
mysql_query("SET character_set_results=utf8", $db);


$result = mysql_query($querymethis) or die("Error in query: $query.".mysql_error());
//rows? or no rows?
if (mysql_num_rows($result)>0) {
//yes, rows!
while(list($title, $link, $descript) = mysql_fetch_row($result)) {
fwrite($rssf, "\t<item>");
printitem($rssf, $title, $link, $descript);
fwrite($rssf, "\t</item>\n");
fwrite($rssf, "\n");
}
}

abduraooft
06-30-2011, 11:11 AM
$unicode = "SET NAMES 'utf8' COLLATE 'utf8_unicode_ci";
mysql_query($unicode);
Check the output after adding a proper error check, like

mysql_query($unicode) or die(mysql_error());

Fugix
06-30-2011, 06:28 PM
comment retracted

Cactuar
06-30-2011, 11:09 PM
Huh. I forgot a single quote mark. I can't believe I didn't notice that yet, all the times I've been over this page. Thank you so much! It's working now. The title is a little wonky but I think I know what to do to fix that. I shall try to use these 'proper error checks' with more regularity.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum