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

  • SEARCH
  • Home
  • 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 8663465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:59:27+00:00 2026-06-12T16:59:27+00:00

I am currently looking to find a solution which I can use to find

  • 0

I am currently looking to find a solution which I can use to find out if selected IP addresses are within a string to replace them with the word private. My problem is that I do not just want to replace always the same IP, but ranges.

For example, I want to find out if a string contains an IP that starts with 123. and if so, change the IP address to the word private

Examples:

123.55.33.10
123.100.10.110
123.1.5.1

The issue is that I don’t know the exact IP addresses and just know how they start, so I can’t censor them by checking the string length etc.

The next issue is that I want to replace various ip’s, for example ones that start with 123. then some that start with 66. and so on. So for my issue, it would be great if you could help me come up with a solution that basically works like:

$ips = array("123.","66.","112."); 

and the solution would basically check that if a string contains one of the array values, then replace the IP with the word private – but not just the 123. but any possible combination as a whole, meaning not just $string = str_replace("123.","",$string);

but replacing the whole IP address with private

Reason for this request:
I am building a small script for a school and I need to replace IP’s with the word private, as the search function returns results with IP addresses and I do not want to display them in the results.

The string could look like:
Hans posted with IP 123.1.1.1 on 10.12.2012

So my mission is showing:
Hans posted with IP private on 10.12.2012

So to sum it up, no matter if the string is:
Hans posted with IP 123.112.12.1 on 10.12.2012 or
Hans posted with IP 123.12.15.12 on 10.12.2012 or
Hans posted with IP 123.24.0.100 on 10.12.2012

the solution would replace any IP’s that start with values from my array with the word private

Thank you for your time reading this 🙂

Edit:

I tried the solutions with this string, but it did not work as expected:

<?php
$ip = "The date is 12.10.2012 and this ip 123.1.2.12 should not show but 144.100.1.11 should show while 66.122.11.9 should not show";
$ip = preg_replace('/^(123 | 66 | 112) \. [\d.]+$/x', "private", $ip);
echo $ip;
?>

What should show in the end would be:

The date is 12.10.2012 and this ip private should not show but 144.100.1.11 should show while private should not show

  • 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-12T16:59:30+00:00Added an answer on June 12, 2026 at 4:59 pm
    $result = preg_replace(
        '/\b             # Start at a word boundary
        (?=              # Assert that the following can be matched:
         [^\d.]*         #  only digits or dots
         \b              #  followed by a word boundary, 
         (?:123|66|112)  #  then one of the three magic numbers
         \b              #  and another word boundary
        )                # End of lookahead
        \d{1,3}          # Match a number
        (?:\.\d{1,3}){3} # Match a dot and a number, three times
        \b               # End the match at a word boundary/x', 
        'private', $subject);
    

    This does not do a sanity check for the validity of IPv4 addresses; it would also match 999.123.999.999. But that check could easily be introduced if necessary.

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

Sidebar

Related Questions

I'm currently looking around to find what's allow and what's not in GAE. Using
I am currently looking for a way to remove fullstops from a string in
I'm currently looking at a hefty Rails test suite. It's nothing I can get
I am looking for a solution which would allow me to code for Linux
I couldn't seem to find a similar question to this. I am currently looking
I am currently looking for a way where I can build a lambda expression
Currently looking into learn new technology and silverlight is on the potential list. However,
I am currently looking to deploy a web forum on the azure platform. I
I am currently looking into a couple of possibilities for a microsite that I
I am currently looking at the C# Metro default controltemplate for scrollbar. And in

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.