Multiple entries in class attribute do not work [closed]

2

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

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

But you're interpreting the div class like this:

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

It interprets alert separated. How can I work with 2 classes or more in a div in php?

    
asked by anonymous 02.07.2016 / 23:40

3 answers

3

It is necessary to delimit where the values for the class attribute begin and end, as is done with the double or double quotation marks, as in echo is using the double, use the double, or use \ to make the escapes:

Option:

Simple 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>"; 
    
02.07.2016 / 23:45
2

Just escape the quotes:

echo "<div class=\"alert alert-success\" role=\"alert\">Logado com sucesso</div>";
    
04.07.2016 / 15:51
0

Just as a complement to @rray's response, as I have no reputation yet to comment, you can simply do that, too:

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

PHP supports the use of both single quotation marks and quotation marks double , and make use of simple, when the string to be contained have many double quotes, it is easier to use simple to encapsulate these.

    
03.07.2016 / 18:54