<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aditya Kothadiya&#8217;s Blog &#187; URL</title>
	<atom:link href="http://adityakothadiya.com/tag/url/feed/" rel="self" type="application/rss+xml" />
	<link>http://adityakothadiya.com</link>
	<description>Entrepreneurship, programming, design, productivity, philosophy and more.</description>
	<lastBuildDate>Sat, 11 Feb 2012 00:22:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Generate sequential strings for URL addresses using PHP</title>
		<link>http://adityakothadiya.com/2009/01/generate-sequential-strings-for-url-addresses-using-php/</link>
		<comments>http://adityakothadiya.com/2009/01/generate-sequential-strings-for-url-addresses-using-php/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 14:30:54 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://adityakothadiya.com/?p=352</guid>
		<description><![CDATA[I&#8217;m working on an interesting project right now, and for this project, I wanted to generate URLs with sequential alphabetic sequence as opposed to using numeric IDs. Using alphabetic string allows me to use short URL addresses with many URL combinations. E.g. If I use numeric indexes, then I can only have 10 possibilities to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on an interesting project right now, and for this project, I wanted to generate URLs with sequential alphabetic sequence as opposed to using numeric IDs. Using alphabetic string allows me to use short URL addresses with many URL combinations. E.g. If I use numeric indexes, then I can only have 10 possibilities to represent http://abc.com/N, where N= 0 to 9. But instead, if I use alphabetic character, I have 26 possibilities where N= a, b, c to z. I don&#8217;t want to add usability issues by using both upper and lower cases of alphabets, so I&#8217;ll stick to lower case addresses only.</p>
<p>So I needed a function which will generate sequential alphabetic strings for URL address based on incremental numbers. So I coded up following function:</p>
<pre class="brush: php; title: ; notranslate">
function getAlphaString($num)
{
  $alpha = '';
  while($num &gt;= 1) {
    $num = $num - 1;
    $alpha = chr(($num % 26)+97) . $alpha;
    $num = $num / 26;
  }
  return $alpha;
}
</pre>
<p>Use this in a for{} loop, and it will give you sequential strings. Or call with individual numbers as shown below, and it will return you appropriate alphabetic string.</p>
<pre class="brush: php; title: ; notranslate">
echo getAlphaString(5) . &quot;\n&quot;;
echo getAlphaString(500) . &quot;\n&quot;;
echo getAlphaString(500000) . &quot;\n&quot;;
echo getAlphaString(50000000) . &quot;\n&quot;;
</pre>
<p>And it produced following output:</p>
<pre class="brush: php; title: ; notranslate">
e
sf
abkpt
dejtlx
</pre>
<p>Hope you&#8217;ll find this function  useful in one of your applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://adityakothadiya.com/2009/01/generate-sequential-strings-for-url-addresses-using-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

