|
-
Jun 2nd, 2007, 03:59 AM
#1
Thread Starter
Lively Member
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
-
Jun 2nd, 2007, 09:56 AM
#2
Hyperactive Member
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);
-
Jun 2nd, 2007, 12:39 PM
#3
Thread Starter
Lively Member
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
-
Jun 2nd, 2007, 12:56 PM
#4
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);
-
Jun 2nd, 2007, 04:03 PM
#5
Thread Starter
Lively Member
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....
-
Jun 2nd, 2007, 07:09 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|