title: User agent header - abbreviation for mysql storing
body: <p>According to this thread, and specially this post: <a href="https://stackoverflow.com/a/6595973/1125465">https://stackoverflow.com/a/6595973/1125465</a>, Microsoft as always shows off. The size of user agent, can be really, really huge.</p>
  
  <p>I'm working on a little visitors library in php, and I want to store user agent information. I cannot decide on the data type and length.</p>
  
  <p><strong>So my question is: have you got any ideas, on how to shorten the user agent, to some "normal" size? (for example 256 chars)</strong>.</p>
  
  <hr>
  
  <p><em>Note:</em> Developers use user agents for detecting the user browser, and operating systems. So according to the linked example, all the stupid numbers from M$ are just... Just are. As always, getting on our nerves. <strong>So the idea is to make a function that shorten the user agent string but is not losing the important information.</strong></p>
  
  <p>I think that such a function should:</p>
  
  <ul>
  <li>Not depend on future updates and new browsers (no hardcoded strings)</li>
  <li>Have a simple mechanism that decide what to delete (for example, if there is a number, comma, number, comma, number, comma, number, ..., it can delete it, it is not interesting).</li>
  <li>And at the end if all the operations still results in too long user agent (lets say 256 chars), there is nothing more to do, so just cut off the rest. This is one per million, so the data can be lost.</li>
  </ul>
  
  <hr>
  
  <p><em>Additional note:</em> I know, that I can make a function that get the browser, and OS type from user agent, and save only these values. But as always such a functions have hardcoded names, and if browser isn't recognized, it for example return "Unrecognized browser'. So in the future everyone must remember about updating these function. And if we save shorten user agent, the information isn't lost (as only the script that is reading the database must have new recognition system). But the entries in database are reliable and consistent, as should be.</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong>
  As there should be some code, and there is a problem with idea, and not the problem with existing code, I will write some minimum code, that I wrote so far ;) :</p>
  
  <pre><code>&lt;?php
      function shorten($useragent, $maxsize = 256) {
          $shorten = $useragent;
          ... // ?
          $shorten = substr($shorten, 0, $maxsize); // the "last hope" cut
          return $shorten;
      }
      echo shorten($_SERVER['HTTP_USER_AGENT']);
  ?&gt;
  </code></pre>