954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Page/Character Encoding Tips

if you are having problems with encoding pages/characters,
try this.


<?php
$servername='localhost';
$dbusername='myusername';
$dbpassword='mypassword';
$dbname='mydatabase';
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");

if(!$link)
{
die("Could not connect to MySQL");
}
mysql_select_db("$dbname",$link) or die ("could not open database");
}
?>


<?php
$Category_SQL = "select * from mytable";
$Category_Result = mysql_query("SET NAMES 'latin5'");
$Category_Result = mysql_query("SET CHARACTER SET latin5");
$Category_Result = mysql_query("SET COLLATION_CONNECTION = 'latin5_turkish_ci'");
$Category_Result = mysql_query($Category_SQL);

while($Category_Write = mysql_fetch_array($Category_Result))
{
?>
◊ <?php print $Category_Write[1]; ?>

<?php
}
?>

fatihpiristine
Posting Whiz in Training
283 posts since Sep 2007
Reputation Points: 6
Solved Threads: 19
 

Wouldn't it be a better idea to use utf8?

php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

man.. it works already... it is just an example for those ppl who have problem with encoding. ;)
you can change it to utf

fatihpiristine
Posting Whiz in Training
283 posts since Sep 2007
Reputation Points: 6
Solved Threads: 19
 

I bet it does and thanks for sharing. I've just dropped in another hint in case it doesn't work for someone.

php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

this one works... enough to collation and character set.

$Category_Result = mysql_query("SET NAMES 'latin5'");
$Category_Result = mysql_query("SET CHARACTER SET latin5");
$Category_Result = mysql_query("SET COLLATION_CONNECTION = 'latin5_turkish_ci'");

fatihpiristine
Posting Whiz in Training
283 posts since Sep 2007
Reputation Points: 6
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You