How to style an echo with CSS?

Asked

Viewed 5,861 times

-1

For example: I want to display a formatted database number:

echo number_format($saldo, 2, ',', '.');

There echo writes: 8,944,664.00

I want to know how I use css in this condition... to show in the part of the screen I want, in the color I want, etc etc.

I learned that way: echo "<div class=\"saldo\">$saldo</div>";

Then I get the class in the CSS I leave the way I want, but with the number_format didn’t work out...

3 answers

3


Puts the content to be printed under single quotes, so you can easily use double quotes in the content:

echo '<div class="saldo">'.number_format($saldo, 2, ',', '.').'</div>';

Or still this way:

echo '<div style="color:red">'.number_format($saldo, 2, ',', '.').'</div>';
  • Ahhh, it worked! Thanks, so much simpler too :)

2

Since the echo allows multiple parameters, can be used as follows:

First form (quotation marks and commas):

echo "<div class=\"saldo\">", number_format($saldo, 2, ',', '.') ,"</div>";

Second form (quotation marks and dots):

echo "<div class=\"saldo\">". number_format($saldo, 2, ',', '.') . "</div>";

Third form (echo shortcut / short open tag) PHP >= 5.4.0:

<?=number_format(12930, 2, ',', '.');?> 

The echo, allows you to pass several parameters. The first form would be the most common, because when you have several parameters, the normal is that they are separated only by commas, and in this case they would be interpreted as a priority. But what should be borne in mind is that the echo is not a function, but a constructor of the language itself.

The third approach does not require the echo, simply the abertura + variavel + fecho.

1

You can also use the . phtml extension in your file and work as if it were an html page just put between <?php ?> or <?= ?> the codes in php(back-end).

  • 1

    Well remembered to mention the way out of PHP mode. There was only one example missing in his of how to use this for what he wants (which is the function, not the variable). Could you explain better about the need for extension change? I think you value the answer if you can clear the 2 points.

Browser other questions tagged

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