What is the correct syntax to turn a variable into Bold or Color (PHP)?

Asked

Viewed 345 times

0

Actually I don’t even know how to ask this correctly, so I’ll try to explain as much as I can to my doubt...

I have the following line of code.

<?php echo strval($tour_availability); ?>

This variable $tour_availability receives a String that is inserted by a user in a common text-field and printed on the following page below.

inserir a descrição da imagem aqui

That is, the user typed "Available" in the text-field and the variable $tour_availability received the String that along with the command echo displays on the screen according to the image.

My Doubt!

1- I can’t find the correct syntax to show "Available" in bold or color, for example: Available in green and Not available in red.

I’ve searched commands like <b> </b> and <strong> </strong> but I couldn’t apply...

I tried commands like that $tour_availability = str_replace(<b>$tour_availability</b>); But honestly I can’t get the right syntax.

If it was just text the commands and work, but as it is variable I’m not getting.

If you can help me I appreciate!

  • 1

    And why don’t you make it as simple as it is <b><?= $tour_availability ?></b>?

  • Anderson, thank you very much haha. It worked fine... I used the function to convert to String since the field only accepted Int and I didn’t even care that I could do so... Thanks!

  • And if bobear is case for CSS even, depending on how this HTML is generated.

1 answer

0


You can put $tour_availability between a tag <b> to give only Bold:

$tour_availability = '<b>'.$tour_availability.'</b>'

To change the colors and other categories you should put inside a <span>:7

$tour_availability = '<span style="font-weight:bold; color: red;">'.$tour_availability.'</span>'

Browser other questions tagged

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