1

I want to add include into echo with variable and css and image, but its not working. Please help.

<?php
    if (isset($_POST['sharebutton'])) {
    $share=$_POST['sharetext'];
        $share=$share;
        echo '<div id="content">'.'<img src="img/sharepropic.png"/>'.$share.include('likecomment.php').'</div>';
    }
    ?>
3
  • 2
    $share=$share? Really? You can't concatenate an include. You'll need to do that as multiple lines. Commented Jun 11, 2013 at 18:03
  • Because they don't know how to use the code formatting here? Commented Jun 11, 2013 at 18:04
  • Yes, I don't know because i just start to learn php, and that's the reason I am here. Commented Jun 11, 2013 at 18:10

1 Answer 1

3

If you want to assign output from an include to a variable you can do this:

ob_start();
include('likecomment.php');
$out = ob_get_contents();
ob_end_clean();

echo '<div id="content">'.'<img src="img/sharepropic.png"/>'.$share.$out.'</div>';
Sign up to request clarification or add additional context in comments.

2 Comments

thank. i got it. Just i need to take another variable for include then only i can add this, right?
@krishnaTORQUE welcome to stack overflow. When somebody answers your question be nice and upvote & accept his answer so others know not to post answers :)

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.