我叫谷歌地理位置服务是这样的:字符编码与file_get_contents()函数/ PHP
$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ïrioRiberio,41-243 - 巴西里约热内卢Praçada Bandeira,20270-180,” 应该是 “R.HilárioRiberio,41-243 - Praçada Bandeira ,里约热内卢,20270-180,巴西”
我使用UTF-8作为网站上的字符编码。但这是无关紧要的,因为phpMyAdmin显示数据与破碎的字符一起输入到数据库中。
如何设置正确的字符编码?
测试#1可以帮助,但它不是100%可靠。我看过太多的真实案例,在存储它之前脚本会破坏数据,并在显示它之前完全“破坏”它。 – 2012-04-09 09:36:25