title: How to create a random string using PHP?
body: <p>I know that the rand function in PHP generates random integers, but what is the best way to generate a random string such as:</p>
  
  <p><strong>Original string, 9 chars</strong></p>
  
  <pre><code>$string = 'abcdefghi';
  </code></pre>
  
  <p><strong>Example random string limiting to 6 chars</strong></p>
  
  <pre><code>$string = 'ibfeca';
  </code></pre>
  
  <p>UPDATE: I have found tons of these types of functions, basically I'm trying to understand the logic behind each step. </p>
  
  <p>UPDATE: The function should generate any amount of chars as required.</p>
  
  <p>Please comment the parts if you reply. </p>