I am experiencing a little problem with my PHP function.
I created a PHP function to deduct 1 SMS credit after 160 characters, 2 SMS credits after 320 characters and so on, but recently I observed that a text of 151 characters or less than 160 deducts 2 SMS credits. I don't know if there is any hidden character or if I did not escape certain strings.
Below is the PHP code:
//=== function to deduct credit per sms
function deduct_sms_credit( $user_id, $msg ) {
$per_sms = 160;
//calculate the no. Of sms pages with ceil() function
$no_pg_sms = ceil( strlen( $msg ) / $per_sms );
$sms_amount = $no_pg_sms;
$query = "SELECT * FROM sms_history WHERE user_id=".$user_id."";
$result = mysql_query( $query );
while( $rs = mysql_fetch_array( $result ) ) {
$remaining = $rs['remaining'] - $sms_amount;
$spent = $rs['spent'] + $sms_amount;
}
$qupdate = "UPDATE sms_history SET `remaining` = ".$remaining.", `spent` = ".$spent." WHERE user_id = ".$user_id."";
mysql_query( $qupdate );
}
I tried sending a text messaging containing this:
Dear customer,we apologise for issues experienced while logging in last wk,follow the link below to reset ur password
http://bit.ly/i5ud1zhm,www.boltsns238.com
It charged me 2 credits instead of one credit. I need help with any PHP function to trim, escape, or solve the problem.