Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:14:35+00:00 2026-06-08T12:14:35+00:00

Ok so after having re-read over my previous post asking for help on this

  • 0

Ok so after having re-read over my previous post asking for help on this one I found I wasn’t making it exactly clear what I was trying to do nor was I pointing out why. I have a site that I’m busy developing which may possibly display messages where people have left their phone numbers (even though this is stupid) and I need to be responsible and make sure should this be the case the numbers are masked. Firstly I need to search through the message text which is stored in a variable $messagetext then I need to use the preg_replace() function to mask parts of the number so its not clear what the number is so if someone were to leave a message and their number was “07921234567” it would appear on the message as “07**12*45**”. How would this be done ? All I would like is to find out what function I’d use to search for the entire number (United Kingdom number) which may start +44 or 07 and what REGEX in the preg_replace() function as all i had was:

$extractednum = preg_replace( "/[0-9]/","*",$extractednum);
echo ($extractednum);

All this does is replace the entire number. The reason why I don’t wanna do this is I also have another site I’m working on to do with social networking privacy and I need to mask parts of the telephone numbers I retrieve for my example.

Hopefully this is more clear and if someone could help me out with some code that would be great!

Anything is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:14:36+00:00Added an answer on June 8, 2026 at 12:14 pm

    I think the regex you are looking for is this:

    (00447|\+?447|07)([0-9]{9})
    

    To mask the phone numbers, you’ll need a custom callback with preg_replace_callback(), like this:

    $extractednum = preg_replace_callback( "/(00447|\+?447|07)([0-9]{9})/", function( $matches) {
        // This will return the number unmodified
        // return $matches[1] . $matches[2]; 
        // Instead, set whichever characters you want to be "*" like this:
        $matches[2][0] = $matches[2][1] = $matches[2][4] = $matches[2][7] = $matches[2][8] = "*";
        return $matches[1] . $matches[2]; 
    } , $extractednum);
    

    You can see it working in the demo. For example, an input of 07921234567 yields 07**12*45** as output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After googling and landing on SO and having read this other question Is it
After having this issue on our websites over secure SSL connections for Office file
This is another question about well disposing objects from .NET. After having read a
I'm still entangled in error handling problems. After having read and tried lots of
... after having just read http://www.cocoadev.com/index.pl?CocoaInsecurity ... I am curious to know about your
After having had a dev PC HD corrupt, I'm considering the idea of making
To start with I'll say I've read the post here and I'm still having
After asking this perl newbie question , I have a perl newbie follow-up. I
From what I've read, this topic has come up several times over the last
So after having read a few different Big Nerd Ranch texts, as well as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.