Skip to content
Advertisement

How to use PHP code in inline CSS in HTML

I’d like to use my PHP code in Inline CSS. Let me show the code:

This is my code:

<div class="col-auto">
    <div class="h5 mb-0 mr-3 font-weight-bold text-gray-800">%22</div>
</div>
<div class="col">
<div class="progress progress-sm mr-2">
    <div class="progress-bar bg-info" role="progressbar"
        style="width: <?php $a=22; echo "$a"; ?>%" aria-valuenow="50" aria-valuemin="0"
        aria-valuemax="100"></div>
</div>

This is what I want to achieve:

enter image description here

But instead, I get this:

enter image description here

What can I do to make CSS read 22 from my PHP code? I want to change the width by changing the PHP code. By the way I’m using Bootstrap.

Advertisement

Answer

masterguru seems to be right, you’re using plain HTML. The code itself is correct, you just need to make sure that the PHP inside the HTML is ran.

This video explains how to serve PHP locally.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement