John Michael Rivera
John Michael Rivera

Reputation: 159

Check Length of Data

Need help. Scenario:

A data will be receive by my php script. What i want is to check the data if it is less than or more than 160 characters. If it is more than 160,the smsvalue will be 2 sms.If it is less than 160,the smsvalue will be 1.

I can create this logic,however I want to be like this: 160 + 160 = 320 right?

if($data>160){
$smsvalue = '1';
}elseif($data->320){
    $smsvalue = '2';    
    }elseif($data->480){
    $smsvalue = '3';    
}

Is there any possible way to check it by loop? because the checking i made is hardcoded only.

Thanks

Upvotes: 0

Views: 236

Answers (1)

OlliverKlozoff
OlliverKlozoff

Reputation: 46

You can just divide the length by 160, and then use ceil to round up to the nearest whole number (ex: 480/160 = 3, 481/160 = 4)

$length = strlen($data);
$smsvalue = ceil($length/160);

Upvotes: 3

Related Questions