How to use css bootstrap class in php code echo

hi friends

I need small help. I want to use <i class="glyphicon glyphicon-off"></i> in php echo code!

Here is working Code

<li><a href="<?php echo(BASE_URL); ?>login.php"><i class="glyphicon glyphicon-off"></i> Sign in</a></li>

Above code is working fine! it is showing an icon of signin. but i want to use between login and logout! code, i have written down this code. how to use this class <i class="glyphicon glyphicon-off"></i>

<?php
            if ($obj_user->login) {

                echo("<li>" . "<a href='" . BASE_URL . "process/process_logout.php'>Logout</a>" . "</li>");
            } else {
                echo("<li>" . "<a href='" . BASE_URL . "login.php'>Login</a></li><li> <a href='" . BASE_URL . "signup.php'>Signup</a>" . "</li>");
            }
            ?>

thanks

Simply by this

<?php
    if ($obj_user->login) {

        echo("<li>" . "<a href='" . BASE_URL . "process/process_logout.php'><i class='glyphicon glyphicon-off'></i>Logout</a>" . "</li>");
    } else {
        echo("<li>" . "<a href='" . BASE_URL . "login.php'>Login</a></li><li> <a href='" . BASE_URL . "signup.php'><i class='glyphicon glyphicon-off'></i>Signup</a>" . "</li>");
    }
    ?>

thanks lot :slight_smile:

welcome

You can also make your life a lot easier if you do something like this.

<?php
if ($obj_user->login) {
?>
<li><a href='<?php print(BASE_URL); ?>process/process_logout.php'><i class='glyphicon glyphicon-off'></i>Logout</a></li>
<?php
} else {
?>
<li>This is the sample "snippet" as you can see.</li>
<li>But boy, I do like to use ' and "</li>
<li><a href='<?php print(BASE_URL); ?>login.php'>Login</a></li><li> <a href='<?php print(BASE_URL); ?>signup.php'><i class='glyphicon glyphicon-off'></i>Signup</a></li>
<?php
}
?>

Then when you want to add something new into one of the 2 HTML lines, you don’t have to struggle at trying to escape what is what. Example of what I mean.

With PHP, you cannot use any single quotes in HTML while being nested in PHP using single quotes. Vice versa for double quotes. So to avoid this and allow PHP and HTML to use single quotes, you would need to escape them like \' which can be very annoying to the eyes (IMO).

So to get away from all the clutters and clean up the mess, you can end the PHP tag, start your HTML stuff, and begin your PHP tags after your HTML stuff. This makes it easy for you to add in single quotes and double quotes at the same time. You can also use PHP within the HTML as you can see in the sample snippet above.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.