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. Link to comment https://forums.phpfreaks.com/topic/289427-preg_match-help-required/ Share on other sites More sharing options...
Ch0cu3r Posted July 4, 2014 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; Link to comment https://forums.phpfreaks.com/topic/289427-preg_match-help-required/#findComment-1483791 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! Link to comment https://forums.phpfreaks.com/topic/289427-preg_match-help-required/#findComment-1483806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.