23 February 2023

How to add color according to first letter of text in PHP?

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

?> 

No comments:

Post a Comment

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...