Use at own risk. Programs haven't been thoroughly tested.

function: extract_macaddress

Regex function to extract a mac address from a string Very usefull for parsing snmp information. Returns a cleanly formatted mac address (if found)

Info

@author Kevin van Zonneveld
@version 1.0
@link http://kevin.vanzonneveld.net
@param (string) $data The haystack to search in

Example

Usage
echo extract_mac($snmp_results);

Outputs
00:0F:EA:80:56:5A

Source Code

download source
<?  
function extract_macaddress($data){
  
  if(!preg_match("/([0-9a-fA-F]{2}[:|\s]){5}([0-9a-fA-F]{2})/",$data,$match))return false;
  return str_replace(" ", ":", trim(reset($match)));
}
?>

Add comment

» Currently away on vacation. I can reply your message the 24th of July 2008. Please post anyway and check back then. Thank you!

for syntax highlighting

[CODE="Javascript"]
your_code_here();
[/CODE]

Replace "Javascript"
with "php", "text", etc.
code (to make sure you are not a spammer)

Comments

No comments. Be the first!