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 create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...