Manuel Pear

Net_MAC::format()

Net_MAC::format() -- Cleanly formats Media Access Control (MAC) addresses

Synopsis

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

chaîne de caractères Net_MAC::format (chaîne de caractères $input [, chaîne de caractères $delimiter=':' [, booléen $uppercase=TRUE]])

Description

This function will format a MAC address into XX:XX:XX:XX:XX:XX format from whatever format is passed to the function. The delimiter (':' in the example above) will be replaced with whatever chaîne de caractères is passed to the $delimiter parameter (default ':').

Paramètres

  • chaîne de caractères $input - The chaîne de caractères containing the MAC Address

  • chaîne de caractères $delimiter - The chaîne de caractères representing the delimiter to use when formatting the MAC Address

  • chaîne de caractères $uppercase - If set to TRUE (default), the alpha characters in the hexadecimal values in the MAC Address will be returned in uppercase. If FALSE, the alpha characters in the hexadecimal values will be returned in lowercase.

Valeur retournée

chaîne de caractères - The formatted MAC Address or FALSE if the syntax of the MAC address is invalid

Note

Cette fonction devrait être appelée de façon statique.

Exemple

Exemple 54-1. Using format()

  1. <?php
  2. require_once "Net/MAC.php";  
  3.  
  4. $macaddr = 'AB:CD:EF:00:11:22';  
  5.  
  6. if (!Net_MAC::check($macaddr)) { 
  7.    echo "$macaddris invalid"; 
  8.    exit;  
  9. }  
  10.  
  11. $mac = Net_MAC::format($macaddr);  
  12. if ($mac) { 
  13.    echo "$mac";  
  14. }  
  15. else { 
  16.    echo "$macaddrcould not be formatted";  
  17. ?> 

This would output the following:

AB:CD:EF:00:11:22

Exemple 54-2. Using format() to get a MAC address with a different delimiter

  1. <?php
  2. require_once "Net/MAC.php";  
  3.  
  4. $macaddr = 'AB:CD:EF:00:11:22';  
  5.  
  6. if (!Net_MAC::check($macaddr)) { 
  7.    echo "$macaddris invalid"; 
  8.    exit;  
  9. }  
  10.  
  11. $mac = Net_MAC::format($macaddr, '-');  
  12. if ($mac) { 
  13.    echo "$mac";  
  14. }  
  15. else { 
  16.    echo "$macaddrcould not be formatted";  
  17. ?> 

This would output the following:

AB-CD-EF-00-11-22

Exemple 54-3. Using format() to get a MAC address with all capital alpha characters

  1. <?php
  2. require_once "Net/MAC.php";  
  3.  
  4. $macaddr = 'ab:cd:ef:00:11:22';  
  5.  
  6. if (!Net_MAC::check($macaddr)) { 
  7.    echo "$macaddris invalid"; 
  8.    exit;  
  9. }  
  10.  
  11. $mac = Net_MAC::format($macaddr, '', true);  
  12. if ($mac) { 
  13.    echo "$mac";  
  14. }  
  15. else { 
  16.    echo "$macaddrcould not be formatted";  
  17. ?> 

This would output the following:

ABCDEF001122

Voir aussi

Net_MAC::check(),


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