Welcome Guest, Not a member yet? Register   Sign In
string helper
#1

[eluser]mr daniel[/eluser]
Hi guys.

In my directory. localhost/system/helpers/string_helper.php

I have
Code:
if ( ! function_exists('random_string'))
{
function random_string($type = 'alnum', $len = 8)
{
  switch($type)
  {
   case 'basic' : return mt_rand();
    break;
   case 'alnum' :
   case 'numeric' :
   case 'nozero' :
   case 'alpha' :

     switch ($type)
     {
      case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
       break;
      case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
       break;
      case 'numeric' : $pool = '0123456789';
       break;
      case 'nozero' : $pool = '';
       break;
     }

     $str = '';
     for ($i=0; $i < $len; $i++)
     {
      $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
     }
     return $str;
    break;
   case 'unique' :
   case 'md5'  :

      return md5(uniqid(mt_rand()));
    break;
   case 'encrypt' :
   case 'sha1' :

      $CI =& get_instance();
      $CI->load->helper('security');

      return do_hash(uniqid(mt_rand(), TRUE), 'sha1');
    break;
  }
}
}

I want to replace the
Code:
case 'nozero' : $pool = '';
       break;
with something that has three words and three numbers in it.


So like
Code:
case 'word' : $pool = '(my)(fun)(zone)(12)(24)(37)';
       break;

Is there a way to group letters and numbers together? I need this for my website as the words must relate to the site in question!


Messages In This Thread
string helper - by El Forum - 07-16-2012, 05:46 PM
string helper - by El Forum - 07-16-2012, 07:01 PM
string helper - by El Forum - 07-16-2012, 07:03 PM
string helper - by El Forum - 07-16-2012, 07:11 PM
string helper - by El Forum - 07-16-2012, 07:44 PM
string helper - by El Forum - 07-16-2012, 08:56 PM
string helper - by El Forum - 07-16-2012, 09:44 PM
string helper - by El Forum - 07-16-2012, 10:02 PM
string helper - by El Forum - 07-16-2012, 10:05 PM



Theme © iAndrew 2016 - Forum software by © MyBB