Net_IPv4::calculate()

Net_IPv4::calculate() – Calculates network information based on an IP address and netmask.

Synopsis

require_once 'Net/IPv4.php';

mixed calculate ( )

Description

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.

Example

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.

Note

This function can not be called statically.

Parse a CIDR address (address/netmask combination). (Previous) Determines whether or not the supplied IP is within the supplied network. (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.