Add color according to first letter of text in PHP
<?php
$name = "jaspreet";
$initial = strtoupper(substr($name, 0, 1)); // Get the first letter and convert it to uppercase
$color = '#' . substr(md5($initial), 0, 6); // Generate a 6-digit hexadecimal color code from the MD5 hash of the initial
echo "<div style='background-color: $color;'>$initial</div>"; // Display the initial inside a div element with the generated color as the background color
?>
Comments
Post a Comment