How do I use two or more colors in the same line of text?

Asked

Viewed 28 times

-2

Good morning everyone, I’m starting to venture into php and html. My question is, if possible html read several Hex color code in one line, mixing them!

For example

Let’s assume I have a php variable in:

$cor = '#00FF00HTML#0000FFPHP';

and the goal is for html to interpret this variable with the corresponding color

<p><?php echo $cor; ?></p>

Upshot

HTMLPHP

(in case HTML turns green, and PHP turns blue)

Note: the example cited, it was only to be clearer the final objective!

  • You can deal with regular expressions looking for the hexas colors in your variable and build the final HTML applying the colors, but with this you run the risk of several delicate cases that would need to be considered, depends on your need.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.