GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Codification issues  XML
Forum Index -> General
Author Message
Anonymous



Hello,

I am having some issues with utf8 charset. I use mysql and php. PHPMyAdmin shows perfectly the name of the cities with special chars (vietnamese, iranian, arabic,..). Some of the special chars i can see it, but not all of them. In my header i have
<meta http-equiv=Content-Type content="text/html; charset=utf-8" />

I was thinking it was something to do with php, but phpmyadmin shows it properly with full special chars support. But in my script i can't make it work. I tried all strings functions, all things about strings convertion, but nothing through.

Anybody could help me?
backbeat



Joined: 16/08/2006 11:06:25
Messages: 5
Offline

i'm sorry i was not logged in.

That was me
noiv



Joined: 10/06/2006 16:36:57
Messages: 19
Location: ExploreOurPla.net
Offline

When you do nothing special with PHP (e.g. multibyte)
it send strings to your website like they are found in the database.

Did you tried to tell the browser to use a special charset?
Does the browser use UTF-8?

noiv - ExploreOurPla.net
[WWW]
Anonymous



Yes, the browser succesfully detects that the charset is utf8. THe fact is that some of the special chars are shown properly, but some others not. Is like if i had something missing to be able to show them all, which is weird as in phpmyadmin can be seen fine.
backbeat



Joined: 16/08/2006 11:06:25
Messages: 5
Offline

Sorry i forgot to log me in again
noiv



Joined: 10/06/2006 16:36:57
Messages: 19
Location: ExploreOurPla.net
Offline

My remote diagnostics capabilities are limited, need more details to give help....

noiv - ExploreOurPla.net
[WWW]
backbeat



Joined: 16/08/2006 11:06:25
Messages: 5
Offline

I'm gonna show you some screenshots:

That is what i got in phpmyadmin


which is fine, but same configuration, and with all utf8 treatments i got this



Doing the same query, same php and apache configuration and same browser config

That is what i mean
noiv



Joined: 10/06/2006 16:36:57
Messages: 19
Location: ExploreOurPla.net
Offline

Well, I see. Same browser, same charset, but different results.
Which code produces bottom screen?
Have you tried a minimal approach like:
Code:
 echo "<html><head></head><body>";
 $res = mysql_query("select a row from the table");
 while ($row = mysql_fetch_object($res)){ echo $row->name . "<br />";}
 echo "</body></html>";
with charset and doctype of course?

noiv - ExploreOurPla.net
[WWW]
backbeat



Joined: 16/08/2006 11:06:25
Messages: 5
Offline

Botton screen has been created with a code similar like the one you have shown.

Code:
 
 <html>
    <head>
        <meta http-equiv=Content-Type content="text/html; charset=utf-8" />
 
 <?
      	$link = mysql_connect ("localhost", "$usert", "$pass")
         	or die ("no me puedo conectar al servidor: " .mysql_error());
 
     	mysql_select_db("edr") or die("No puedo seleccionar la base de datos");
 
 
        	$query = "Select name FROM `geonames` WHERE `country_code` LIKE 'VN' GROUP BY name LIMIT 0 , 30 ";
   	$result = mysql_query($query) or die("No puedo realizar la consulta");
 
 
       echo "<table>";
       while($row=mysql_fetch_array($result)){
 
           echo "<tr><td>".$row[name]."</td></tr>";
       }
       echo "<table>";
 mysql_close($link);
 
 ?>
 


Thank you very much indeed for your attention
noiv



Joined: 10/06/2006 16:36:57
Messages: 19
Location: ExploreOurPla.net
Offline

Hmmm, only one last point:
Code:
header('Content-Type: text/html; charset=utf-8');
as the first line of anything else in PHP. If this not helps,
I have no more ideas, except install everything again
Lo siento mucho.

noiv - ExploreOurPla.net
[WWW]
backbeat



Joined: 16/08/2006 11:06:25
Messages: 5
Offline

Hi fellas!

I've been working hard on trying to solve my issue and finally i got it!!

It is a very stupid thing that once you see it you say "oh Come on, how fool i am" but it's been a big while to try to solve it.

The solution is that once you select and connect to the database you have to add the next code in -> <-

Code:
 
         $link = mysql_connect ($server, $user, $pwd) or die ("No puedo conectar a la base de datos: " .mysql_error());
 
         mysql_select_db($datenbank) or die("No puedo seleccionar la base de datos");
         ---> @mysql_query("SET NAMES 'utf8'"); <----
 


That was what i had missing in my code and phpmyadmin did have.

I hope it help someone else.

Cheers
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.5 © JForum Team