Laurize
Laurize

Reputation: 213

php echo inside $output

I'm trying to get a specific page content from a page and i need to insert this php code:

i tried this:

$output .= <<<HTML

            </div>
        </div>
<div id="hometabs">
echo getPageContent(8);
    </div>
<div class="clear"></div>
    </div>

    <div class="bottom_shadow"></div>

</div>
HTML;

but it doesn't work.. i even tried:

getPageContent(8);
echo getPageContent(8)
<?php echo getPageContent(8);?>

still it didn't

note: i already have code for the getPageContent i'm just not sure why when viewing on my browser, this code: echo getPageContent(8) shows up instead of executing it.

Upvotes: 2

Views: 4764

Answers (1)

Jared Cobb
Jared Cobb

Reputation: 5267

The syntax you're using is called a Heredoc in PHP. It's a special way to build a string and put it into a variable but it allows you to have line breaks and quotes and other cool things (like using php variables inside the string).

Unfortunately you can't execute functions inside a heredoc unless you do some special and creative syntax changes to your code. Here's another SO question that is similar to what you're facing: Calling PHP functions within HEREDOC strings.

If I were doing this, I'd probably change the syntax up a bit like this (see if this works for you):

$the_content = getPageContent(8);

$output .= <<<HTML

        </div>
    </div>
    <div id="hometabs">
        $the_content
    </div>
    <div class="clear"></div>
    </div>

    <div class="bottom_shadow"></div>

    </div>
HTML;

Upvotes: 3

Related Questions