Net_IPv4::calculate()
Net_IPv4::calculate() – Calculates network information based on an IP address and netmask.
Synopsis
require_once 'Net/IPv4.php';
mixed calculate (
)
Описание
Fully populates the object properties based on the IP address and netmask/bitmask properties. Once these two fields are populated, calculate() will perform calculations to determine the network and broadcast address of the network.
Пример
Calculating broadcast and network address
<?php
require 'Net/IPv4.php';
// create IPv4 object
$ip_calc = new Net_IPv4();
// set variables
$ip_calc->ip = "192.168.1.10";
$ip_calc->netmask = "255.255.255.0";
/* alternative method with numerical values:
$ip_calc->long = 3232235786;
$ip_calc->bitmask = 24;
*/
// calculate
$error = $ip_calc->calculate();
if (!is_object($error))
{
// if returned true, output
echo "Your network address: ".$ip_calc->network."<br />";
echo "Your broadcast address: ".$ip_calc->broadcast."<br />";
}
else
{
// otherwise handle error
echo "An error occured: ".$error->getMessage();
}
?>
Return value
boolean
- Returns TRUE on success,
PEAR_Error on failure.
Замечание
This function can not be called statically.