if($_SERVER['REQUEST_METHOD']==='POST') {
// get post data
foreach(array_keys($_POST) as $key){
$value=$_POST[$key];
// $data[$key]=$value;
if(preg_match('/_/',$key)){
$key1=preg_replace('/\_/',' ',$key);
$substitute=1;
}
else{
$substitute=0;
}
// experimental, broken, returns non-utf8
// for multiple selects etc.
if(is_array($value)){
$data[$key]=array();
if($substitute){
$data[$key1]=array();
}
foreach($value as $entry){
$entry=stripslashes($entry);
if($substitute){
array_push($data[$key1],$entry);
}
array_push($data[$key],$entry);
}
}
else{
$value=stripslashes($value);
if($substitute){
$data[$key1]=$value;
}
$data[$key]=$value;
}
// utf8_decode($post_data);
$post_data=http_build_query($data);
}
// $data=preg_replace('/\&$/','',$data);
// call url and pass POST data
$page=do_post_request($url,$data,$user_login);
// $page=utf8_decode($page);
header('Content-Type:text/html; charset=utf-8');
if(preg_match('/aspdf\=true/',$url)){
output_pdf($page['content']);
}
else{
print($page);
}
}
I have a slightly complex problem. This php script (snippet of) sends post data to a perl cgi script via CURL, which mostly works fine EXCEPT for Multiple Select Data. The only way to make Multiple Select Data (i.e. requiring a nested array which CURL will not accept in the POST field) accepted is to flatten it and use a query string. Hey great! except... UTF8 data gets mangled in the process - it CANNOT be simply fixed buy using utf8_decode (well, it APPEARS to except the data received by the Perl CGI script is corrupted so that even though the return result and output of the php looks fine my Perl interface & data source is messed up - it works in all utf8 fine so the Perl script is not the problem). Tried forcing curl to use multipart instead of x-www that just died...
I have researched lots of other threads on this topic here already, they all suggest flattening the array which will NOT work for me unless there is a way round this utf8 problem, or they suggest using utf_decode which as I say leaves me corrupt data.