How can you replace 2 to 3 digits of an IP address with # in PHP?

To replace 2 to 3 digits of an IP address with # in PHP, you can use a combination of string manipulation functions like explode() and implode(), along with substr_replace(). By splitting the IP address into its individual parts, you can then replace a portion of each part with the desired number of # characters.

$ip_address = "192.168.1.100";
$parts = explode('.', $ip_address);
foreach ($parts as &$part) {
    $part = substr_replace($part, str_repeat('#', min(3, strlen($part))), 0, min(3, strlen($part)));
}
$masked_ip = implode('.', $parts);
echo $masked_ip;