PHP IPV6 CIDR计算主机总数

I am looking for a php script which will give the total number of hosts for an IPV6 IP address in CIDR format. I know that there are similar posts about this but I have not been able to get any of them to work properly so far. Any help is appreciated.

If you have the prefix in CIDR notation then you know the prefix length. The bits usable for hosts are the bits not defined by the prefix. So it's easy to calculate the number:

Take the prefix length (the part after the slash), subtract it from the address length (128), and calculate 2 to the power of the result.