<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Michal Král</title>
    <description>The latest articles on Forem by Michal Král (@kralik12).</description>
    <link>https://forem.com/kralik12</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F21797%2F85ec1aeb-60ac-446f-abc8-9ad2177d1422.jpg</url>
      <title>Forem: Michal Král</title>
      <link>https://forem.com/kralik12</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kralik12"/>
    <language>en</language>
    <item>
      <title>Generate Human-Friendly Random Codes in PHP with Crockford’s Base32</title>
      <dc:creator>Michal Král</dc:creator>
      <pubDate>Tue, 30 Sep 2025 18:24:28 +0000</pubDate>
      <link>https://forem.com/kralik12/generate-human-friendly-random-codes-in-php-with-crockfords-base32-fob</link>
      <guid>https://forem.com/kralik12/generate-human-friendly-random-codes-in-php-with-crockfords-base32-fob</guid>
      <description>&lt;p&gt;Generating random codes sounds easy — until real people have to read, type, or say them out loud. Suddenly &lt;code&gt;O&lt;/code&gt; looks like &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;l&lt;/code&gt; looks like &lt;code&gt;1&lt;/code&gt;, and half your support tickets are about users mistyping their coupon or entry code.  &lt;/p&gt;

&lt;p&gt;To solve this, I built a small PHP library that generates &lt;strong&gt;human-friendly random strings&lt;/strong&gt; using &lt;strong&gt;Crockford’s Base32 alphabet&lt;/strong&gt;. It’s perfect for things like &lt;strong&gt;coupon codes, ticket entry codes, invite tokens, or any other short identifiers&lt;/strong&gt; where clarity matters just as much as randomness.  &lt;/p&gt;

&lt;p&gt;👉 GitHub repo: &lt;a href="https://github.com/CheckThisCloud/CrockfordRandom" rel="noopener noreferrer"&gt;CheckThisCloud/CrockfordRandom&lt;/a&gt;  &lt;/p&gt;




&lt;h2&gt;
  
  
  Why Crockford’s Base32?
&lt;/h2&gt;

&lt;p&gt;When generating codes for humans to type in or read back, you don’t want people misreading &lt;code&gt;O&lt;/code&gt; as &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;l&lt;/code&gt; as &lt;code&gt;1&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
Crockford’s alphabet solves this by removing ambiguous characters while keeping the string compact and case-insensitive.  &lt;/p&gt;




&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Generate random strings of any length.
&lt;/li&gt;
&lt;li&gt;Ideal for human-facing codes: &lt;strong&gt;tickets, coupons, invites, promo codes&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;Output uses only unambiguous characters.
&lt;/li&gt;
&lt;li&gt;Built on PHP’s modern &lt;code&gt;Random\Randomizer&lt;/code&gt; class.
&lt;/li&gt;
&lt;li&gt;Tiny footprint — easy to drop into any project.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Example usage
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;CheckThisCloud\CrockfordRandom\CrockfordRandom&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$random&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CrockfordRandom&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$random&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// Example output: 9XF7T2K4HZ&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Bonus: SillyNames 🎉
&lt;/h3&gt;

&lt;p&gt;I’ve also built another micro-library: [CheckThisCloud/SillyNames]((&lt;a href="https://github.com/CheckThisCloud/SillyNames" rel="noopener noreferrer"&gt;https://github.com/CheckThisCloud/SillyNames&lt;/a&gt;)&lt;br&gt;
.&lt;br&gt;
It generates random two-word names in the style of Docker container names (e.g. brave_panda, sleepy_hedgehog).&lt;br&gt;
Useful for test data, logs, or giving projects some personality.&lt;/p&gt;

&lt;p&gt;Feedback is very welcome 🙏&lt;/p&gt;

</description>
      <category>php</category>
      <category>opensource</category>
      <category>devtools</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
