views:

48

answers:

2

Hello

I have main site to which i put code using require function, but when i add php functions into it, they appear as plain text. The php code is rather long so i won't paste it here. Could anyone help me with that?

Thanks

ok i am adding some code:

require part with only one function:

<?php
$content=<<<EOF
echo 'hello';
EOF;
require 'whatever.php';
?>

and main part:

<?php
echo <<<CONT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

<html>
    <head>
        ...
    </head>
    <body id="body">
        <div id="container">
        $content
        </div>
        <div id="add_func">
        </div>
    </body>
</html>
CONT;
?>
+4  A: 

Make sure that You wrap your code in <?php.....?> tags.

Update:

No need to use the heredoc syntax for what you are doing, you could modify you code like this:

<?php
  echo 'hello';
  require 'whatever.php';
?>

And:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
    <head>
        ...
    </head>
    <body id="body">
        <div id="container">
        <?php echo $content; ?>
        </div>
        <div id="add_func">
        </div>
    </body>
</html>
Sarfraz
Yeah, i have done that. Even the simple require like that :<?php$content=<<<EOFecho 'hello';EOF;require '...php';?>gives me: echo 'hello'; on the siteboth files are wrapped in <?php ... ?>
kasper
@kesper: Make sure that there is no SPACE/INDENTATION before ending `EOF`. Also it would be easier if you could post your code in your question above.
Sarfraz
that code should give echo \'hello\', you can't use functions/language constructs from within heredocs.
Cags
+1  A: 

just get rid of heredoc

require part

<?php
echo 'hello';
require 'whatever.php';
?>

main part

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

<html>
    <head>
        ...
    </head>
    <body id="body">
        <div id="container">
        <?php echo $content ?>
        </div>
        <div id="add_func">
        </div>
    </body>
</html>

that's all
PHP is not Perl, heredoc is useless here, even if properly used. Just never use this ugly syntax.

Col. Shrapnel
but i would have to use echo ''; on each line ?
kasper
@kasper do you see echo on each line here? PHP can output HTML directly http://www.php.net/manual/en/language.basic-syntax.phpmode.php
Col. Shrapnel
oh sorry, bad question,thanks for answer
kasper
looks like my browser ate your code lines :)
kasper
@kasper this is very handy feature of PHP, making php both engine and template language. Main part gather the data and then include template part, which consists of HTML and basic programming instructions.
Col. Shrapnel
ok i'm beeing dumb or something but why call undefinied $content?
kasper
@kasper you have to define $content somewhere of course.
Col. Shrapnel