title: Repeating a function
body: <p>This is a follow-up question to a question <a href="https://stackoverflow.com/questions/4514168/unique-alpha-numeric-generator">I posted here</a>.</p>
  
  <p>I am using the following code to give users a unique id:  </p>
  
  <pre><code>function NewGuid() { 
      $s = strtoupper(uniqid(rand(),true)); 
      $guidText = substr($s,0,8) . '-' . substr($s,8,4) . '-' . substr($s,12,4). '-' . substr($s,16,4). '-' . substr($s,20); return $guidText; 
  } 
  
  $Guid = NewGuid();
  echo $Guid;
  
  $alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
  
  function base_encode($num, $alphabet) { 
      $base_count = strlen($alphabet); 
      $encoded = '';
  
      while ($num &gt;= $base_count) {
          $div = $num/$base_count;
          $mod = ($num-($base_count*intval($div)));
          $encoded = $alphabet[$mod] . $encoded;
          $num = intval($div);
      }
  
      if ($num) $encoded = $alphabet[$num] . $encoded;
      return $encoded;    
  }
  
  function base_decode($num, $alphabet) { 
      $decoded = 0;
      $multi = 1;
  
      while (strlen($num) &gt; 0) {
          $digit = $num[strlen($num)-1];
          $decoded += $multi * strpos($alphabet, $digit);
          $multi = $multi * strlen($alphabet);
          $num = substr($num, 0, -1);
      }
  
      return $decoded;
  }
  
  echo base_encode($Guid, $alphabet);
  </code></pre>
  
  <p>So, if a id that is generated is already in use, i want this code to be able to repeat until a completely new id is generated and entered into the database.  IN addition i am new to programming, so please feel free to elaborate ;)</p>
  
  <p>Any thoughts? Thanks.</p>