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 video slider with cuncks of videos without download all videos?

 Create video slider with cuncks of videos without download all videos function custom_video_slider_shortcode() { $slider_id = 'vide...