Pergunta

I have these codes in PHP to do reverse geocode[get address from latitude, longtitude]:

<?php

$lon = 100.753;
$lat = 13.69362;

$addr = getAddress($lat,$lon);

echo "Address: ".$addr;

function getAddress($RG_Lat,$RG_Lon)
{
  $json = "http://nominatim.openstreetmap.org/reverse?format=json&lat=".$RG_Lat."&lon=".$RG_Lon."&zoom=27&addressdetails=1";
  $jsonfile = file_get_contents($json);
  $RG_array = json_decode($jsonfile,true);

  foreach ($RG_array as $name => $value)
  {
      if($name == "display_name")
      {
          $RG_address = $value;
          break;
      }
  }

  return $RG_address;
}
?>

The result is a string like this:

Short term parking, ท่าอาà¸à¸²à¸¨à¸¢à¸²à¸™à¸ªà¸¸à¸§à¸£à¸£à¸“ภูมิ, สมุทรปราà¸à¸²à¸£, จังหวัดสมุทรปราà¸à¸²à¸£, ราชอาณาจัà¸à¸£à¹„ทย

I saved this string into mysql database with the field type to store this is utf8_general_ci.

My question is how can I display this string correctly in Thai Characters on web after taken it out from database?

FYI, the actual address in Thai Character is like this:

Short term parking, ท่าอากาศยานสุวรรณภูมิ, Samut Prakan, Samut Prakan Province, Thailand

Thank you.

Foi útil?

Solução

Seems like you store the wrong string in the first place because you didn't decode it correctly. If you take a look at the query result in your browser you can see that the result contains unicode escape sequences like \u0e17\u0e48\u0e32\u0e2d. These sequences have to be decoded first. If you enter them into a web converter like http://rishida.net/tools/conversion/ you will start seeing the correct characters. You will have to perform a similar conversion before storing the string in your database.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top