PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.20.2
Last Build: October 16, 2017 12:40pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
file
graph
html
mail
math
misc
mobile
script
string
system
time
psUniqKeyTxt()
Uniq Key Text


Description:

This function generates a uniq key based on a string that is passed to it.
Original designed to have a human type key to allow easier debugging.


Usage:

psUniqKeyTxt(STRING);


Example:


$s = "Mercedes Benz";
$key = psUniqKeyTxt($s);
print "$s -> $key\r\n";

will output:
Mercedes Benz -> MercBenz-galkvv




Code:

function psUniqKeyTxt($str)
{
$ary = str_word_count($str,1);
$nums = preg_replace('/[^0-9]/', '', $str);
$ary[] = $nums;

$wLen = 5;
if ($cnt > 2) { $wLen = 4; }
if ($cnt > 3) { $wLen = 3; }
if ($cnt > 4) { $wLen = 2; }
if ($cnt > 5) { $wLen = 1; }

$out = "";
foreach ($ary as $key=>$val)
{
$out .= substr($val,0,$wLen);
}

$hv = crc32($str);
$hvc = base_convert($hv,10,36);

$res = $out . "-" . $hvc;
return $res;
}



Changlelog:

03/10/2016 - added variable sizing the the sub str, and added numbers as an item

See Also

  psUniqKey()
And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site