I'm using BulkSMS which is a SMS service and I want to get how many messages I have left using the URL response.
This is the URL (with password removed):
https://www.bulksms.co.uk/eapi/user/get_credits/1/1.1?username=<username>&password=<password>
This then outputs something similar to:
0|2000.00
According to the documentation the first part refers to error messages and the second part refers to no. of messages remaining: status_code|status_description
So using cURL and explode I can get the URL response split via an array, but my question is how do I output the 2000.00 (status_description) as I would only want the 0 (status_code) for error checking?
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
$array = explode('|', $data);
print_r($array);
}
If it helps this is what the function outputs:
Array ( [0] => 0 [1] => 2000.00 )
Also I know I could use substr and strpos to get the remaining messages as shown below, but I would like to use the status_code for error checking.
$remaining_sms = substr($data, strpos($data, "|") + 1);
echo $remaining_sms;
echo $array[0];andecho $array[1];