Rails 3和PHP的合作问题
我正在尝试使用php5编写服务,并使用Rails 3使用它。Rails 3和PHP的合作问题,php,ruby-on-rails,ruby-on-rails-3,character-encoding,Php,Ruby On Rails,Ruby On Rails 3,Character Encoding,我正在尝试使用php5编写服务,并使用Rails 3使用它。 这就是我要做的 PHP: // $DATA is an associative array that contains an Ukrainian characters. // I am converting all of values with Ukrainien characters to utf-8 using **utf8_encode** function header('Content-Type: json; charse
这就是我要做的 PHP:
// $DATA is an associative array that contains an Ukrainian characters.
// I am converting all of values with Ukrainien characters to utf-8 using **utf8_encode** function
header('Content-Type: json; charset=utf8');
echo json_encode($DATA);
exit;
url = URI.parse("http://127.0.0.1/searchInvStat/showclaimdetails.php?app_n=#{@claim.claim_db[:app_number]}")
req = Net::HTTP::Get.new(url.request_uri)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
@states = ActiveSupport::JSON.decode( res.body )
PHP转换字符串,如\u00ca\u00e2\u00e8\u00f2\u00e0\u00ed\u00f6\u00b3\u00ff
轨道:
// $DATA is an associative array that contains an Ukrainian characters.
// I am converting all of values with Ukrainien characters to utf-8 using **utf8_encode** function
header('Content-Type: json; charset=utf8');
echo json_encode($DATA);
exit;
url = URI.parse("http://127.0.0.1/searchInvStat/showclaimdetails.php?app_n=#{@claim.claim_db[:app_number]}")
req = Net::HTTP::Get.new(url.request_uri)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
@states = ActiveSupport::JSON.decode( res.body )
但在结果页面上,我得到了一个字符串,比如Îèñèèèèèèèèèèèèèèèèèóèè
有人能帮我吗 我找到了解决方案:
不要使用
json\u encode($DATA)
你应该使用iconv(“windows-1251”,“UTF-8”,“$DATA['OUTDOCS'][$i]['regNumb'])代码>如果在浏览器中打开PHP脚本会发生什么?看起来还好吗?是的,我想是的,我看到了u00ca\u00e2\u00e8\u00f2\u00e0\u00ed\u00f6\u00b3\u00ff字符串,我想没问题