I'm using curl to post data which is retrieved from a PDO query. Each time I successfully get the expected response except that time I'm adding string with spaces. I have tried to add all the possible encoding headers for UTF8. With no result. I have searched and surfed the related questions like This Question with no luck. Below are sample of my code..
public function collectorFetcher(){
$data = $this->pdo->prepare(" select * bla bla ");
$data->execute();
$result = $data->fetchAll();
foreach($result as $key => $value){
//echo $result[$key]['customer_name'];die;
curl_setopt($this->ch, CURLOPT_URL, "http://API_URL/'customerRecords':[{'arabicData':'".$result[$key]['arabicData']."'}]}");
curl_setopt($this->ch, CURLOPT_HEADER, 0);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml;charset=utf-8"));
$response = curl_exec($this->ch);
$data = json_decode($response);
var_dump($data);die;
if(isset($data->beanResponse->inserted)){
$this->log("Insert Status: ".$data->beanResponse->inserted);
}else if(isset($data->beanResponse->message)){
$this->log("Collector Fetcher message: ".$data->beanResponse->message);
}else{
$this->log("Collector Fetcher General Error: ".var_dump($data));
}die;
} }