PHP 8.5.0 Alpha 2 available for testing

Voting

: max(seven, six)?
(Example: nine)

The Note You're Voting On

ac221 at sussex dot ac dot uk
17 years ago
Some SNMP agents return mac addresses as hex encoded ascii.

e.g. '30:30:3a:31:37:3a:66:32:3a:39:62:3a:34:36:3a:30:65'

Each octet represents 4 bits of the mac address.
Some vendors may also encode the separators into the string.

Heres a function to convert these strings back into plain hex.

<?php
$hexStr
= '30:30:3a:31:37:3a:66:32:3a:39:62:3a:34:36:3a:30:65';

echo(
str_replace(':','',hexStr2Ascii($hexStr)));

function
hexStr2Ascii($hexStr,$separator = ':'){
$hexStrArr = explode($separator,$hexStr);
$asciiOut = null;
foreach(
$hexStrArr as $octet){
$asciiOut .= chr(hexdec($octet));
}
return
$asciiOut;
}
?>

Outputs: '0017f29b460e'

<< Back to user notes page

To Top