formatting an array of mobile numbers

Posted by Kyle Hudson on Stack Overflow See other posts from Stack Overflow or by Kyle Hudson
Published on 2010-04-16T10:11:55Z Indexed on 2010/04/16 10:13 UTC
Read the original article Hit count: 259

Filed under:
|
|
|

Hi,

I am creating a SMS app the following code is supposed to:

  1. check if the mobile/cell number is 11 characters long.
  2. check if the number starts with 07.

If neither of these conditions are met, it should remove the number from the array.

So the following numbers would be valid:

07123456789,07123456790,07123456791,07123456792,07123456793,07123456794

However the following wouldn't (and need to be removed):

0801458,07855488,6695522214124514

    $param["number"] = "07123456789,07123456790,07123456791,07123456792,07123456793,07123456794,0801458,07855488,6695522214124514";
    $number = explode(',', $param["number"]);
foreach($number as $num){
    if (!substr_compare($num, "07", 0, 3, false)) {
        unset($num);
    }
    elseif (substr_compare($num, "07", 0, 3, true)) {
        if(strlen($num) == 11) {
            $li .= "447" . substr($num, 2) . ',';
        }
    }
}
$il .= substr($li, 0, strlen($li)-1); 
echo $il;

//  $request = substr($request, 0, strlen($request)-1); 
//  return $n;
}

I also need to remove the final comma from the result.

Any help will be appriciated.

Thanks,

Kyle

© Stack Overflow or respective owner

Related posts about arrays

Related posts about explode