ted_chou12 Posted February 5, 2007 Share Posted February 5, 2007 an ip looks roughly like this: 123.456.789.012 i want the forth combination to be censored to xxx, is it possible? Ted Quote Link to comment Share on other sites More sharing options...
effigy Posted February 5, 2007 Share Posted February 5, 2007 <pre> <?php // Run 10 tests. for ($i = 0; $i < 10; $i++) { // Generate an IP. for ($j = 0; $j < 4; $j++) { $ip_pieces[] = rand(1, 255); } $ip = join($ip_pieces, '.'); // Run regex. printf('%15s => %-15s<br>', $ip, preg_replace('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.)\d+/', '\1xxx', $ip)); // Reset. $ip_pieces = null; } ?> </pre> Quote Link to comment Share on other sites More sharing options...
mjlogan Posted February 6, 2007 Share Posted February 6, 2007 a messy looking one-liner, using no expressions, kind of not the point of this forum substr(implode("", array(substr($myIP, 0, strrpos($myIP, ".")+1), 'xxx')), 0, strlen($myIP)); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.