Last active
January 7, 2019 08:05
-
-
Save MahdiY/7a9dc67d50a8e628024ee7e58249f5a0 to your computer and use it in GitHub Desktop.
String to html hex color function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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