"\\n", "\r" => "\\r")); $arr['message'] = preg_replace('/[\x00-\x1F\x7F\xA0]/u', '', $arr['message']); $arr['uri'] = $variable['sms_api_uri']; $arr['key'] = $variable['sms_api_key']; $arr['pwd'] = $variable['sms_api_password']; $arr['body'] = $variable['sms_api_request_body']; $arr['success'] = $variable['sms_api_success_response']; $arr['http_header'] = $variable['sms_api_http_header']; switch ($arr['uri']) { case 'https://api.philsms.com/outbound/v1': print_r(philSMS($arr)); break; case 'https://www.itexmo.com/php_api/api.php': print_r(itextmo($arr)); break; default: echo "sms uri not found"; } function itextmo($array_data) { $replace_parameter = array( '[no]' => $array_data['receiver'], '[msg]' => $array_data['message'], '[key]' => $array_data['key'], '[pwd]' => $array_data['pwd'] ); $final_template = strtr($array_data['body'], $replace_parameter); // $headers = json_decode($array_data['http_header'], true); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $array_data['uri']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_decode($final_template, true)); // if (count($headers) > 0) { // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // } $result = curl_exec($ch); return $result; } function philSMS($array_data) { $replace_parameter = array( '[no]' => $array_data['receiver'], '[msg]' => $array_data['message'], '[key]' => $array_data['key'], '[pwd]' => $array_data['pwd'] ); $final_template = strtr($array_data['body'], $replace_parameter); $headers = json_decode($array_data['http_header'], true); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $array_data['uri']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $final_template); if (count($headers) > 0) { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } $result = curl_exec($ch); // return $result; $response = json_decode($result, true); // return $response; return $response['status'] == 201 ? 0 : $result; }