Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't get text to encode properly -- MySQL

    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)

    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:
    Code:
    AddDefaultCharset UTF-8
    
    <FilesMatch "\.(htm|html|css|js)$">
    AddDefaultCharset UTF-8
    </FilesMatch>
    ...but to no avail.

    Help?

    The relevant portion:
    PHP Code:
    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");
        }
    }
    Last edited by Cactuar; 06-30-2011 at 10:11 PM. Reason: Resolved

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,854
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    $unicode = "SET NAMES 'utf8' COLLATE 'utf8_unicode_ci";
    mysql_query($unicode);
    Check the output after adding a proper error check, like
    PHP Code:
    mysql_query($unicode) or die(mysql_error()); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Jun 2011
    Posts
    103
    Thanks
    0
    Thanked 13 Times in 13 Posts
    comment retracted

  • #4
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •