0
我一直在試圖解決這個問題很長一段時間,但我認爲我需要一個超越知識來做到這一點。curl do_post_request從iso-8859-1更改字符集到utf-8
我有一個編碼爲iso-8859-1的PHP頁面。 當有人在其上註冊時,郵件被髮送到管理員,並且用戶被插入到數據庫中。
我需要一些數據並將它們傳遞給另一個函數。 我使用curl包含了do_post_request函數,它幾乎完美地工作。
問題是,當我使用這個功能傳遞數據時,所有重音字符都被刪除。 我無法更改首頁的編碼,因爲否則電子郵件和數據庫中的插入會受到影響。我需要找到一個解決方案,使用utf-8標題發佈數據。
這裏的簡化代碼:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
...
...
// insert in the db
$result = mysql_query($query,$conn);
function do_post_request($url, $data, $optional_headers = null){
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
$test = do_post_request($crmURL, $crmData);
mail('[email protected]','New user',"body message",'From: Me <[email protected]>');
</body>
</html>
任何想法怎麼辦? 歡呼