Search code examples
phphtmlecho

How to style a echo function with multiple variables


I would like my code to display two variables on the same echo function, however, I want them to style them differently. Making the 'id' smaller and a different color. I do not know how to separate the two variables so I can add some code in-between.

I tried to use a second echo function, but then the 'id' displays at the bottom, separate from the 'quote' function.

echo "<p class='dash'>---------</p>","<p class='center' style='color:white' align='center'>" .$row['quote'] .$row['id'];

The output will just display like this (bold text for output):
--------
"This is the quote variable"1


However, I need is displayed like this:

-------
"This is the quote variable"
1


So basically what is needed is some way to add style to the second one. (I already styled the first one)


Solution

  • Another way which eliminates use of dot concatenation operator:

    <?php
    $row["quote"] = "This is the quote";
    $row["id"] = 1;
    $p = [];
    $p[0] = "<p class='dash'>---------</p>\n";
    $p[1] = "<p class='center' style='color:white' align='center'>$row[quote]<br>\n$row[id]</p>\n";
    echo $p[0],$p[1];
    

    live code here

    Example HTML implementation:

    .dash {
      color: blue;
      font-weight: 300;
    }
    
    .center {
      text-algin: center font-weight:900;
    }
    
    body {
    background:navy
    }
    <p class='dash'>---------</p>
    <p class='center' style='color:white' align='center'>This is the quote<br> 1
    </p>