curl do_post_request从iso-8859-1更改字符集到utf-8

问题描述:

我一直在试图解决这个问题很长一段时间,但我认为我需要一个超越知识来做到这一点。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> 

任何想法怎么办? 欢呼

我还在工作之上,但我越来越疯狂......

我想不通我怎么可以转换从ISO-8859-1形式发送到UTF-字符集8个字符。

换句话说,如果我有2页A和B和A在ISO并发送参数为B的UTF-8,像“òùìù”这样的参数没有保存。

但是,如果我创建变量iside B像“òùìù”这个数据当前被保存。

因为我不能改变A,有没有办法将数据从A转换过来?