Jump to content

preg_match help required.

Go to solution Solved by Ch0cu3r,

Recommended Posts



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);
    $phone = '0'.$matches[2];
    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
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.