Adamhn jo
Adamhn jo

Reputation: 1

html in php variable

I am trying to store this div in a PHP variable, like given below

<div class="col-xl-12 col-xs-12 icon-div" style="height: 15vw;  display: flex; align-items: right; justify-content: center; margin: auto; padding-left: 0px;padding-right: 0px;" >
    <a class="fa-pos" href="https://m.facebook.com/<?php echo $facebook ?>"> <i class="fab fa-facebook-square fa-3x" style="color: #3b5998;" ></i> </a> 
    <p class="user-id-display"> <?php echo $facebook; ?> </p> 
    <a href="https://m.facebook.com/<?php echo $facebook ?>" class="myButton">Open</a> 
    </div>

as given below

<?PHP $facebook_html='<div> "the html code above..." </div>' ?>

then echo the HTML like <?PHP echo $facebook_html; ?>

the HTML and style works fine but the PHP code inside doesn't work, it simply printing the PHP code

Upvotes: 0

Views: 50

Answers (2)

Toxnyc
Toxnyc

Reputation: 1350

Make the whole thing into a PHP string.

<?php
$facebook = "myfacebook";

$facebook_html = "
    <div>
        <div class='col-xl-12 col-xs-12 icon-div' style='height: 15vw;  display: flex; align-items: right; justify-content: center; margin: auto; padding-left: 0px;padding-right: 0px;' >
            <a class='fa-pos' href='https://m.facebook.com/$facebook'> <i class='fab fa-facebook-square fa-3x' style='color: #3b5998;' ></i> </a> 
            <p class='user-id-display'>$facebook</p> 
            <a href='https://m.facebook.com/$facebook' class='myButton'>Open</a> 
        </div>
    </div>";

echo $facebook_html;

Upvotes: 1

Rahul Koshti
Rahul Koshti

Reputation: 186

You need to concat your HTML code to PHP.. Please check below example.

<?php
$html = "<div>Hii There</div>";
$html.=PHP CODE;
echo $html;
?>

Upvotes: 0

Related Questions