title: Smart pagination algorithm
body: <p>I'm looking for an example algorithm of smart pagination. By smart, what I mean is that I only want to show, for example, 2 adjacent pages to the current page, so instead of ending up with a ridiculously long page list, I truncate it.</p>
  
  <p>Here's a quick example to make it clearer... this is what I have now:</p>
  
  <pre><code>Pages: 1 2 3 4 [5] 6 7 8 9 10 11
  </code></pre>
  
  <p>This is what I want to end up with:</p>
  
  <pre><code>Pages: ... 3 4 [5] 6 7 ...
  </code></pre>
  
  <p>(In this example, I'm only showing 2 adjacent pages to the current page)</p>
  
  <p>I'm implementing it in PHP/Mysql, and the "basic" pagination  (no trucating) is already coded, I'm just looking for an example to optimize it... It can be an example in any language, as long as it gives me an idea as to how to implement it...</p>