-9

I have this html code with php variable the text will be display in color black but I don't know how to make the variable to be in color red

here is the code

<br>Your Intrest Rate is: ".$interest_rate."%\n<br>

when I do

<br>Your Intrest Rate is: ".<a color=red>$interest_rate</a>."%\n<br>

the page stops working

How can I do this please advise?

Cœur
  • 37,241
  • 25
  • 195
  • 267
NICK
  • 15
  • 6

4 Answers4

1

I cannot see PHP tags or PHP code, but assuming this is a string inside PHP tags (since there is no problem without the anchor tag), your problem is the HTML tags outside the string.

Do this:

<br>Your Intrest Rate is: <span style='color:red'>".$interest_rate."%</span><br>
Phiter
  • 14,570
  • 14
  • 50
  • 84
  • it perfectly work. so basically when I have a variable I can not use a – NICK Nov 07 '16 at 15:57
  • No, you can use ` – Phiter Nov 07 '16 at 15:58
  • thanks a lot but now I am running into another problem see when I try
    Your Intrest Rate is: ".$interest_rate."%
    I am trying to align the variable right its still not working
    – NICK Nov 07 '16 at 16:01
  • You must do those things with style parameters. Take a look: http://www.w3schools.com/html/html_styles.asp – Phiter Nov 07 '16 at 16:22
  • print("

    Your monthly income is: $".$monthlyincome1."\n"); I used it exactly how they said it is not working

    – NICK Nov 07 '16 at 16:31
  • The styling will depend on many factors. In your case, probably missing a parent div with a set width. You could do a tutorial on css on codeacademy, you'll learn quick and will surely master the element styling. – Phiter Nov 07 '16 at 16:39
1

change this:

<br>Your Intrest Rate is: ".<a color=red>$interest_rate</a>."%\n<br>

to this if your outside a php tag:

<br>Your Intrest Rate is: ".<a color=red><?php $interest_rate ?></a>."%\n<br>

and if your inside a php tag:

<br>Your Intrest Rate is: ".<a color=red>".$interest_rate."</a>."%\n<br>

and be sure that the variable('$interest_rate') isset

Blueblazer172
  • 588
  • 2
  • 15
  • 44
0

You must tell the server to parse the PHP code as PHP code, using PHP tags:

<br>Your Interest Rate is: <a style='color:red;'><?php echo $interest_rate; ?>%</a><br>
Kevin_Kinsey
  • 2,285
  • 1
  • 22
  • 23
0

Provided your actually able to view the $interest_rate variable, you should use a <span> or something similar to get your text to appear red.

<br>Your Intrest Rate is: ".<span style="color: #ff0000;"><?php echo $interest_rate; ?></span>."%\n<br>

Captain Squirrel
  • 237
  • 5
  • 15