From 6b01e6afaed0d0772a16a1743cfbf1407d7c8844 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 4 Jun 2023 14:19:28 +0000 Subject: [PATCH] Fix php8 uncaught fatal error: Unsupported operand types string * int --- includes/functions.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 35d285cf..7618eeb2 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -52,11 +52,15 @@ function mask2cidr($mask) */ function cidr2mask($cidr) { - $ta = substr ($cidr, strpos ($cidr, '/') + 1) * 1; - $netmask = str_split (str_pad (str_pad ('', $ta, '1'), 32, '0'), 8); - foreach ($netmask as &$element) - $element = bindec ($element); - return join ('.', $netmask); + $ipParts = explode('/', $cidr); + $ip = $ipParts[0]; + $prefixLength = $ipParts[1]; + + $ipLong = ip2long($ip); + $netmaskLong = bindec(str_pad(str_repeat('1', $prefixLength), 32, '0')); + $netmask = long2ip($netmaskLong); + + return $netmask; } /**