How do I put an html tag inside the php code to format the text there?

Asked

Viewed 1,736 times

3

I have the following code and I wanted to tag <font> </font> for example to format the user.

<?php
    session_start();
    echo "Usuario: ". $_SESSION['usuarioNome'];    
?>

2 answers

3

Joins HTML to this string, for example:

<?php
    session_start();
    echo "<strong>Usuario:</strong> ". $_SESSION['usuarioNome'];    
?>

It will appear in the browser like this:

User: Lauriana

1

Close the php tag, write html normally, and call the variable with an echo $Var name. In this case, I created a p, and within it I added a span to customize whatever css is needed.Color, font, margin, etc.

<?php
    session_start();

    // atribuí uma variável ao teu _SESSION.
    // Não precisava, só quis reduzir o código de chamada.
    $username = $_SESSION['usuarioNome'];    
?>

<p>
    Olá,
        <span class="user-name">
            <?php
                // Escreve a variável
                echo $username;
            ?>
        </span>
</p>

In your css file you add the class added to span.

<style>
    .user-name{ font-weight: bold; }
</style>

He’ll show off like this:

Hello, Hugo

  • Try to put a brief explanation of what you did and how it works.

  • Ready @Francisco, documented.

Browser other questions tagged

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