Hi guys,
Need some help with php. This is my code:
<div class="letter-block">MS</div>
<div class="letter-block">JD</div>
<div class="letter-block">KS</div>
<div class="letter-block">JR</div>
<div class="letter-block">GW</div>
<div class="letter-block">FE</div>
What i need is to change the background color of the div's above, based on the first letter of the word they contain. For example if the first letter is M then the background color of the div must be #ff0088, if the first letter is K then the then the background color of the div must be #ff0000 etc.
Any idea ?
Frontend Dev / UX-UI Designer / Illustrator / Father / Linux Enthusiast / Minimalist
Hi, you need tell more details about process. Why need be like... detecting first letter to change the background color? Explain the reason.
Of course, directly you can add different class names with space separator.
examples: class="letter-block MS", class="letter-block KS". With some php conditional added, will display what you need.
But if you are using a php function is better add HTML inside function with variables to your background colors, with your conditionals.
For other hand, I no ideia if these DIVs will appears all together on same page, or only one will be displayed, and if will be something randomized, etc.
Explain better your idea / process if you can.
Hi [member=67]fog[/member]. I was testing some ideas for the new theme of osclass and i just need to get the initial letters of some strings and print them in loop. However, finally i used the php function
preg_split
and then the
$string[0]
and worked perfect. The only problem i have is with non-latin characters. Tried many ways like mb_split but no luck. The output is like that
��
.
Anyway i 'll try to figure it out. (I hope lol).
Frontend Dev / UX-UI Designer / Illustrator / Father / Linux Enthusiast / Minimalist
I never passed by that situation before with non-latin chars.
Maybe this comments can help in something, or not..
https://www.php.net/manual/en/function.utf8-encode.php#45226
Good luck with theme, I hope you can solve it 🙂
OK finally i made it. Everything works perfect!!!! PHP rocks 8) Thank u [member=67]fog[/member]
Frontend Dev / UX-UI Designer / Illustrator / Father / Linux Enthusiast / Minimalist
You're welcome!
The merit is totally yours 🙂