zairyaab Posted July 3, 2014 Share Posted July 3, 2014 Hi, I am fairly new to PHP, I am tryin to put a code together that would see my incoming CLI as 44 and remove the 44 from it and add a 0 to it. I have managed to do this so far, now I am stuck, as any number thats not matching the length (10 digits ) or is not starting with 44 is also not forwarded to my database for query. $input = ($cid); if(preg_match('/^(44|0)(\d{10})$/',$input,$matches)){ $phone = '0'.$matches[2]; }else die("Invalid Phone Number") ; What I would like is that any number starting with 441234567890 to become 01234567890, but should not involve 10 digits criteria. Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted July 4, 2014 Solution Share Posted July 4, 2014 So you only want to apply it to numbers with more than 10 digits, if it is more replace 44 at the beginning of the number with a zero Simple substr replacement should do the trick. $num = '441234567890'; // number greater than 10 digits and beings with 44 if(strlen($num) > 10 && substr($num, 0, 2) == 44) { $num = '0' . substr($num, 2); // ignore the first two digits and prepend the number with a zero } echo $num; Quote Link to comment Share on other sites More sharing options...
zairyaab Posted July 4, 2014 Author Share Posted July 4, 2014 Thanks a lot @Ch0cu3r you saviour! That code is exactlly what I was lookin for! You genius, saved me! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.