Convert a DELL Service Tag into Express Service Tag (PHP)

in #php4 years ago (edited)

image.png

At times in our systems support roles we need to call/work with DELL while working with any DELL hardware and we need to provide them the Service Tag or Express Service Tag, This Simple PHP script can be used to translate a DELL Service Tag into the Express Service Tag.

<?php

function ExpressServiceTag($service_tag)
{
    $val = 0; //our return value

    try
    {
        $szRange = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $aRange = str_split($szRange); //convert range string to array

        $sTag = strtoupper($service_tag); //convert service tag to uppercase
        $sTag = strrev($sTag ); //reverse the service tag
        $aTag = str_split($sTag); //convert service tag to array

        $iLen = count($aTag); //get length of array

        //loop through each character in the reversed service tag
        for ($i=0; $i<$iLen; $i++)
        {
            $iPos = strpos($szRange, $aTag[$i]); //find position in array of character
            $sum = pow(36, $i); //base raised to the power of exp
            $val += $iPos * $sum; //add the position * sum
        }
    }
    catch(Exception $e)
    {
        echo 'Error: ' . $e->getMessage();
    }

    return $val;
}

$service_tag = "1J94H51";
$express_service_tag = ExpressServiceTag($service_tag);

echo "Express Service Tag: " . $express_service_tag . "<br>";
?>

or if you prefer one line:

echo $express_service_tag = base_convert($service_tag, 36, 10);

Coin Marketplace

STEEM 0.26
TRX 0.25
JST 0.039
BTC 94802.39
ETH 3313.10
USDT 1.00
SBD 3.32