- floor: documentation ( source)
- fmod: documentation ( source)
<?php
function getShortUrl(int $id)
{
$chars = "123456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
$length = strlen($chars);
$id = intval($id);
if ($id < 1) {
return 0;
}
$code = "";
while ($id > $length - 1) {
$fmod =intval(fmod($id, $length));
$code =$chars[$fmod].$code;
$id = floor($id / $length);
}
$code = $chars[intval($id)] . $code;
return $code;
}
$short_url=getShortUrl(14992139347739999999999);
echo "sinadme.com/".$short_url;