J
J
jaffrey2016-11-04 20:40:04
PHP
jaffrey, 2016-11-04 20:40:04

How to output DIV via ECHO?

You need to check for the presence of a variable and, if so, display a block with buttons. I do it like this:

<?php if(isset($row)) {   //проверяем наличие
                    echo 
                    '<div class="uk-button-group">
                            <a class="uk-button uk-button-link uk-button-large" href="../auth/signup.php">Регистрация</a>
                            <a class="uk-button uk-button-success uk-button-large uk-margin-left" href="../auth/login.php" style="background-color: #ffb433;"onmouseover="this.style.backgroundColor='#eb8d00';" onmouseout="this.style.backgroundColor='#ffb433';"><i class="uk-icon-lock uk-margin-small-right"></i> Войти</a>'
                    </div>'
                    }
                ?>

But everything is somehow strange stands out. Apparently due to the fact that there are still single quotes in the code (or maybe not because of this). Attention to the question: how to arrange everything correctly?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
holfza, 2016-11-04
@jaffrey

<?php if(isset($row)) :  ?>
                    <div class="uk-button-group">
                            <a class="uk-button uk-button-link uk-button-large" href="../auth/signup.php">Регистрация</a>
                            <a class="uk-button uk-button-success uk-button-large uk-margin-left" href="../auth/login.php" style="background-color: #ffb433;"onmouseover="this.style.backgroundColor='#eb8d00';" onmouseout="this.style.backgroundColor='#ffb433';"><i class="uk-icon-lock uk-margin-small-right"></i> Войти</a>'
                    </div>
<?php  endif;  ?>

K
Kirill Zhilyaev, 2016-11-04
@kirill_782

heredoc
Alternative syntax

V
Vasily Nazarov, 2017-02-02
@vnaz

onmouseover="this.style.backgroundColor='#eb8d00';"
First, according to the standards, single quotes do not need to be put here at all.
Secondly, if you need single ones inside 'string', you should escape them:
echo 'String with \'in quotes\' inside';
Thirdly, you can (for me, it's much better) write like this:

<?php if(isset($row)) {   //проверяем наличие ?>
                    <div class="uk-button-group">
                            <a class="uk-button uk-button-link uk-button-large" href="../auth/signup.php">Регистрация</a>
                            <a class="uk-button uk-button-success uk-button-large uk-margin-left" href="../auth/login.php" style="background-color: #ffb433;"onmouseover="this.style.backgroundColor='#eb8d00';" onmouseout="this.style.backgroundColor='#ffb433';"><i class="uk-icon-lock uk-margin-small-right"></i> Войти</a>'
                    </div>
<?php } ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question