Skip to content

Instantly share code, notes, and snippets.

@MahdiY
Last active January 7, 2019 08:05
Show Gist options
  • Save MahdiY/7a9dc67d50a8e628024ee7e58249f5a0 to your computer and use it in GitHub Desktop.
Save MahdiY/7a9dc67d50a8e628024ee7e58249f5a0 to your computer and use it in GitHub Desktop.
String to html hex color function
<?php
function s2c( $str ) {
return substr( md5( $str . "snippets.ir" ), -6, 6 );
}
$str = 'snippets.ir';
print '<span style="background-color:#' . s2c($str) . '">' . $str . '</span>';
$str = 'mahdiy.ir';
print '<span style="background-color:#' . s2c($str) . '">' . $str . '</span>';
$str = 'php';
print '<span style="background-color:#' . s2c($str) . '">' . $str . '</span>';
<?php
function s2c( $str ) {
echo $code = dechex( crc32( $str . "snippets.ir" ) );
$code = substr( $code, -6, 6 );
return $code;
}
$str = 'snippets.ir';
print '<span style="background-color:#' . s2c($str) . '">' . $str . '</span>';
$str = 'mahdiy.ir';
print '<span style="background-color:#' . s2c($str) . '">' . $str . '</span>';
$str = 'php';
print '<span style="background-color:#' . s2c($str) . '">' . $str . '</span>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment