Jump to content

Text Color


gacon

Recommended Posts

I am writing a short function, that will change the textcolor if the texts are in the bracket, such as <Text need in red color>, then the rest of the text that are not in the bracket, will be in black color, I tried but no work at all, any ideas what wrong with the codes. Thank you.

<?
function WriteText($TextColor, [color=red]$Color[/color])
{
  $TextColor = str_replace("<",'<font style="color: [color=red]#$Color[/color]; font-weight: bold; FONT-SIZE=18pt;">', "$TextColor");
  $TextColor = str_replace(">", '</font>', "$TextColor");

  return ($TextColor);

}

$text = "<If texts inside the brackets, then assigns to new color> If texts are outside of it, will be default color.";

echo WriteText("$text", "#F11A1A");

?>
Link to comment
https://forums.phpfreaks.com/topic/27395-text-color/
Share on other sites

Well when I thought more about it,

I came up with the following:

[code]
<?php
$temp = '~`~';
$TextColor = "Hello how are you?  <This should be red> is it?  How about <this one>?";
$TextColor = str_replace('>',$temp,$TextColor);
$Color = 'C80000';
$TextColor = str_replace('<','<font style="color: #'. $Color .'; font-weight: bold; FONT-SIZE=18pt;">',$TextColor);
$TextColor = str_replace($temp,'</font>',$TextColor);
echo $TextColor;
?>
[/code]

It temporarily changes ">" to a temporary string.  Because when you replace "<" with the font string, you ADD another ">".  We don't want THAT one to be changed.
Link to comment
https://forums.phpfreaks.com/topic/27395-text-color/#findComment-125332
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.