0

I have PHP code as

$message = str_replace("{eventlinkURL}",$eventlinkURL,$message);

I want to set color to the $eventlinkURL variable. I tried using <font>

echo "<font style='background:red'> <font color ='red'>
    $message = str_replace('{eventlinkURL}',$eventlinkURL,$message); />"; 

but no success. How do I set color to the variable?

  • 3
    That last one won't work, PHP inside strings isn't executed, you should look up how to join strings together in PHP ( string concatenation ), then look up CSS classes and stylesheets rather than using inline styles – Tom J Nowell Mar 6 '15 at 18:37
1
  1. do not use <font> html tag, it is old and i'm not even sure if can work in modern browsers. instead use <span> (for inline text) or <p> (for paragraph).

  2. php and html can work together but there's an appropriate way to write it. generally speaking, html code is wrapped with double quotes "html" and php with periods .php.:

    echo "html code here".php code here."more html here";
    
  3. i advice you first to set a variable for the $message and after it call the var inside the echo code. that way it would be a cleaner code.

so here is a final solution for you:

$message = str_replace('{eventlinkURL}',$eventlinkURL,$message); 
echo "<span style='background:red;'>".$message."</span>";

good luck,

Ituk

  • i have tried your suggestion, but no working. actually message is an array, contains infomration in different text lines. Can't we set color direclty to eventlinkURL vairable. so that once the eventlinkURL variable will be fetched, the color will start showing. – Gagan Mar 6 '15 at 16:59
  • i understand, if $message is an array my code won't work for you. array is just a way to store data, so you cannot style the array itself - you can only style its output. anyway, in order to help more, please paste the whole code including the $eventlinkURL. something is not clear to me yet. – Ituk Mar 6 '15 at 22:20
0

Instead of using style background:red; use color:red; like the following.

$message = str_replace('{eventlinkURL}',$eventlinkURL,$message); 
echo "<span style='color:red;'>".$message."</span>";

Not the answer you're looking for? Browse other questions tagged or ask your own question.