Manuel Pear

Net_IPv4::calculate()

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

Synopsis

  1. <?php
  2. require_once 'Net/IPv4.php
  3. ?> 

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.

Exemple

Exemple 54-1. Calculating broadcast and network address

  1. <?php
  2.  
  3. require 'Net/IPv4.php';  
  4.  
  5. // create IPv4 object
  6. $ip_calc = new Net_IPv4();  
  7.  
  8. // set variables
  9. $ip_calc->ip = "192.168.1.10";  
  10. $ip_calc->netmask = "255.255.255.0";  
  11.  
  12. /* alternative method with numerical values:
  13. $ip_calc->long = 3232235786;
  14. $ip_calc->bitmask = 24;
  15. */  
  16.  
  17. // calculate
  18. $error = $ip_calc->calculate();  
  19. if (!is_object($error))  
  20. {  
  21. // if returned true, output
  22. echo "Your network address: ".$ip_calc->network."<br />";  
  23. echo "Your broadcast address: ".$ip_calc->broadcast."<br />";  
  24. }  
  25. else  
  26. {  
  27. // otherwise handle error
  28. echo "An error occured: ".$error->getMessage();  
  29. }  
  30.  
  31.  
  32. ?> 

Valeur retournée

boolean - Retourne TRUE en cas de succès, un objet PEAR_Error en cas d'échec.

Note

Cette fonction ne peut pas être appelée de façon statique.


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique