Results 1 to 6 of 6

Thread: display unicode data in php

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    India
    Posts
    117

    display unicode data in php

    sir
    i created a database with following table in MySQL.
    Code:
    Field		Type	Collation
    Name		Varchar(50)   utf8_bin
    Age		int(11)
    i want to store unicode data in my table. when i insert unicode data into my table it worked correctly. but my proble is that when i write code in php to display the contents of table i get only question marks in the place of unicode data. why this happens... my code is below... please go through it and help me....

    PHP Code:
    <?php
    mysql_connect
    ("localhost","root","");
    mysql_select_db("mydata1");
    $result=mysql_query("SELECT * FROM mytable");
    ?>
    <!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>
    <TITLE>
    Testing
    </TITLE>
    <meta http-equiv="content-type" content="text/html:charset=utf-8"/>
    </HEAD>
    <BODY>
    <TABLE border="1" cellpadding="2">
    <TR>
    <TH> NAME</TH>
    <TH>AGE</TH>
    </TR>
    <?php
    while ($row=mysql_fetch_array($result)) {
    echo 
    "<tr>";
    echo 
    "<td>"  .  $row['Name']  .  "</td>";
    echo 
    "<td>" $row['Age'] . "</td>";
    echo 
    "</tr>";
    }
    mysql_free_result($result);
    mysql_close();
    ?>
    </TABLE>
    </BODY>
    </HTML>
    Last edited by penagate; Jun 2nd, 2007 at 04:26 AM. Reason: Added code tags

  2. #2
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: display unicode data in php

    Look in my sig and download cowzilla, a working example of this is below. Here is the reader's digest ver.


    PHP Code:
    //PHP 4 tested
    //I have had problems with this on different servers
    //CentOS vs OS X running x86 distro vs PowerPC.

    $this->charset "utf-8";   //defaults to utf-8      

    ....

    //default to UTF-8 change it ISO-8859-1
          //php defaults to ISO-8859-1
          //I think this only works for php 4 and up
          
          
    iconv_set_encoding("internal_encoding"$this->feed->charset);
          
    iconv_set_encoding("output_encoding"$this->feed->charset);
          
    iconv_set_encoding("input_encoding"$this->feed->charset); 

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    India
    Posts
    117

    Re: display unicode data in php

    sir,
    i am new to php.... so will u please tell me how to change my code to support unicode.
    thank u
    ran

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: display unicode data in php

    he just did.

    change the class variable names to something not referencing a class (eg. "$encoding" or something similar).

    PHP Code:
    $charset "utf-8";

          
    iconv_set_encoding("internal_encoding"$charset);
          
    iconv_set_encoding("output_encoding"$charset);
          
    iconv_set_encoding("input_encoding"$charset); 

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    India
    Posts
    117

    Re: display unicode data in php

    sir....
    i dont understand... where i will put the above code in my code... what changes i made in my code to display unicode... plz help me....

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: display unicode data in php


Posting Permissions

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



Click Here to Expand Forum to Full Width