0

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

2 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

2 Comments

: syntax error, unexpected 'CODE' (T_STRING) in line , something wrong with $html.=PHP CODE;
Hey PHP CODE means you have to write php code their like variables etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.