我这样称呼谷歌地理定位服务:
$querystring = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng=".$row['lat'].",".$row['lng'];
$context = stream_context_create(array(
'http' => array(
'timeout' => 10
)
));
$f = file_get_contents($querystring, 0, $context);
$f = json_decode($f);
if(!isset($f->status) || $f->status != 'OK') continue;
$f = $f->results[0];
$location = $f->formatted_address;
然后我将位置插入数据库:
//add the location to the database
$sql = "INSERT INTO `wp_postmeta`
(`meta_id`, `post_id`, `meta_key`, `meta_value`)
VALUES
(
NULL,
'".intval($row['ID'])."',
'location',
'".mysql_real_escape_string($location)."'
)";
if($location) $insert = mysql_query($sql);
问题:当我编辑 wordpress 帖子时,有些字符显示不好。例如“R. Hilário Riberio, 41-243 - Praça da Bandeira, Rio de Janeiro, 20270-180, Brazil”应该是“R. Hilário Riberio, 41-243 - Praça da Bandeira, Rio de Janeiro , 20270-180, 巴西"
我在网站上使用 UTF-8 作为字符编码。但这无关紧要,因为 phpMyAdmin 显示数据也以损坏的字符输入到数据库中。
如何设置正确的字符编码?