Author Topic: IP address last code censored.  (Read 1168 times)

0 Members and 1 Guest are viewing this topic.

Offline ted_chou12Topic starter

  • Devotee
  • Posts: 1,481
  • Gender: Male
  • Hitman Hits
    • View Profile
    • NetFriending
IP address last code censored.
« on: February 05, 2007, 12:55:51 PM »
an ip looks roughly like this: 123.456.789.012
i want the forth combination to be censored to xxx, is it possible?
Ted
Currently working on a website called NetFriending.co.cc, it is a free social networking site, features such as guestbook, blogs, are fully customizable in NetFriending, also has a forum to help you get to know others, if you are interested in the site, the url is: NetFriending.co.cc Hope everyone can get involved because the site is still quite new, so not much people are there at the moment, please feel free to leave a comment there or send a message to our staff. Register Here The link above is for registeration, it is 100% Free and Safe, everyone there is friendly and you can build your network. Photo sharing upload your own photos as well!!!

Offline effigy

  • Staff Alumni
  • Freak!
  • *
  • Posts: 7,301
  • Gender: Male
  • We must be the change we wish to see in the world.
    • View Profile
Re: IP address last code censored.
« Reply #1 on: February 05, 2007, 01:20:45 PM »
Code: [Select]
<pre>
<?php
// Run 10 tests.
for ($i 0$i 10$i++) {
// Generate an IP.
for ($j 0$j 4$j++) {
$ip_pieces[] = rand(1255);
}
$ip join($ip_pieces'.');
// Run regex.
printf('%15s => %-15s<br>'$ippreg_replace('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.)\d+/''\1xxx'$ip));
// Reset.
$ip_pieces null;
}
?>

</pre>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

Offline mjlogan

  • Enthusiast
  • Posts: 122
    • View Profile
    • PHP Snippets
Re: IP address last code censored.
« Reply #2 on: February 06, 2007, 10:57:45 AM »
a messy looking one-liner, using no expressions, kind of not the point of this forum  ;)


substr(implode("", array(substr($myIP0strrpos($myIP".")+1), 'xxx')), 0strlen($myIP));
« Last Edit: February 06, 2007, 11:05:12 AM by mjlogan »