What is the right way to add a button to the php file

Asked

Viewed 54 times

0

I need to put a button in my php file where I will use to register. Follow the code.

echo "<button type=\'"button"'\ class=\'"btn btn-default btn-lg"'\>";
        echo "<span class=\'"glyphicon glyphicon-plus"'\ aria-hidden=\'"true"'\></span> Inserir";
    echo "</button>";

What’s the right way to do it ?

2 answers

2


You don’t need that, Renan. Close the PHP routine with ?> and adds the button in the same HTML language.

But if it’s really necessary to do what you want:

echo "<button type='button' class='btn btn-default btn-lg'><span class='glyphicon glyphicon-plus' aria-hidden='true'></span> Inserir </button>";

Always think so:

" Single quotes 'within' double-quote "

or

' Double quotes "within" plain quote '

2

Look for more html and less php. An example:

....
?>
<button type="button" class="btn btn-default btn-lg <?php echo $algumaClasse; ?>">
    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
        <?php echo $algumaAcaoParaBotao; ?>
</button>
<?php
....

This would be the best way.

Browser other questions tagged

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