Convert Dell service tags and express service tags with PHP

I was given the task at my real job of creating some code to find the service tag from the express service tag of Dell laptops. We only had recorded the express service tag for the 100+ laptops and needed to have the service tag in a project we were working on. I was given some very basic information about the relationship between the two and came up with the following code. With this code you can convert service tags into express service tags and the other way around. It uses a base 36 style formating.

<?php
/*
Author: Daniel Kassner
Website: http://www.danielkassner.com
*/
function convertExpress($tag) {
  $index = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','e');
  
  for($i=10; $i>=0; $i--) {
    $digits[$i] = '0';
    for($k=1; $k<=36; $k++) {
      $tmp = (pow(36, $i)) * $k;
      $tmp2 = $tag - $tmp;
      if($tmp2 < 0) {
        $tmp = (pow(36, $i)) * ($k-1);
        $digits[$i] = $index[$k-1];
        $tag -= $tmp;
        break;
      }
      
      if($tmp2 == 0) {
        $digits[$i] = $index[$k];
        $tag -= $tmp;
        break;
      }   
    }
  }
  $leading = 1;
  foreach($digits as $digit) {
    /*if($digit != '0') {
      $num .= $digit;
    }*/
    if($leading) {
      if($digit != '0') {
        $leading = 0;
        $num .= $digit;
      }
    } else {
      $num .= $digit;
    }
  }
  return $num;
}
?>

To use this code you could use:

<?php
echo convertExpress('(YOUR EXPRESS SERVICE TAG HERE');
?>

Make sure you only use numbers this field.

To get the express service tag from the service tag use the following function:

<?php
/*
Author: Daniel Kassner
Website: http://www.danielkassner.com
*/
function convertTag($tag) {
  $tag = strtoupper($tag);
  $index = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  $count = strlen($tag);
  $count2 = $count - 1;
  for($i=0; $i<$count; $i++) {
    $digits[$count2] = substr($tag, $i, 1);
    $count2--;
  }
  $numb = 0;
  for($i=0; $i<count($digits); $i++) {
    if($i==0) {
      $m = 1;
    } else {
      $m = pow(36, $i);
    }
    $key = array_keys($index, $digits[$i]);
    $tmp = ($m * $key[0]);
    $numb += $tmp;
  } 
  return $numb;
}
?>

To use this code you can use:

<?php
echo convertTag('(YOUR SERVICE TAG HERE)');
?>
  • Facebook
  • Digg
  • del.icio.us
  • Google Bookmarks
  • BlinkList
  • FriendFeed
  • LinkedIn
  • MySpace
  • Slashdot
  • StumbleUpon
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email

Comments are closed.

Switch to our mobile site