PHP Salt


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

Version: 2.33.2
Last Build: December 29, 2023 20:28pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
db
file
graph
html
mail
math
misc
mobile
script
string
system
time
web
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;
$cnt = count($ary);
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:

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