Multiple entries in class attribute do not work

Asked

Viewed 61 times

2

I want to show a simple Alert in php with bootstrap but I’m not getting the code is this:

echo "
<div class=alert alert-success role=alert>Logado com sucesso</div>
"; 

But you’re playing the div class like that:

<div class="alert" alert-success="" role="alert">Logado com sucesso</div>

He plays the alert separate. How I can work with 2 classes or more in a div in php?

3 answers

3


It is necessary to delimit where the values for the attribute begin and end class this is done as with the quotes can be the single or double, as in the echo is using the doubles, use the single ones or use \ to make the escapes:

Option:

Single quotes:

echo "<div class='alert alert-success' role='alert'>Logado com sucesso</div>"; 

Escapes:

echo "<div class=\"alert alert-success\" role=\"alert\">Logado com sucesso</div>"; 

2

Just slip the quotes:

echo "<div class=\"alert alert-success\" role=\"alert\">Logado com sucesso</div>";

0

Just as a complement to @rray’s reply, because I don’t have a reputation yet to comment, you can just do it, too:

echo '<div class="alert alert-success" role="alert">Logado com sucesso</div>';

PHP supports both the use of single quotes as in double quotes, and make use of the simple ones, when the string to be contained has many double quotes, it is easier to use the simple to encapsulate these.

Browser other questions tagged

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