I have few sets of code to display right side of my webpage. I am using this place to show some user information and some short of ads. For ads I am using that code in my database. Now the problem is that I want to display one external php file which is located in the same directory where I am trying to include or require this php file.
But I dont know why this is not working. I tried with iframe
that works fine but I want to use php include
but it is not working .please tell where I am doing mistake. Here is my code:
if (is_array($data['blocks'])) {
$output .= '<div id="appside">';
foreach($data['blocks'] as $block) {
if (is_array($block)) {
$output .= '
<div class="block">';
if ($block['title']) {
$output .= '<div class="block_title">'.$block['title'].'</div>';
}
$output .= '<div class="block_content">
'.$block['content'].
'</div>
</div>
';
}
}
$output .= get_gvar('theme_block_sidebar').
'<div><?php include("/home/xxxxxxx/public_html/xxxxxxxa.php"); ?></div>
</div>
';// end of app_sidebar
I tried with all short of alternatives but its printing raw php code. i开发者_运维问答ts not getting executed. I tried to put <?php include(\'/home/xxxxxxx/public_html/xxxxxxxa.php\'); ?>
and all other sort of alternatives but its printing raw php code.
'<div><?php include("/home/xxxxxxx/public_html/xxxxxxxa.php"); ?></div>
PHP won't execute inside a string (which is all the above is).
You can't really concatenate an include statement (unless the included file returns something via return
). Given I can't tell if your code snippet is inside a function or how it's executed, my best solution is to use output buffering.
$output .= get_gvar('theme_block_sidebar') . '<div>';
ob_start();
include "/home/xxxxxxx/public_html/xxxxxxxa.php";
$output .= ob_get_contents();
ob_end_clean();
$output .= '</div>'
if the file you wish to include is in the same directory as this file, then you should include the filename only
<?php include('filename.php'); ?>
if it is in a higher level or in a directory or a sub-directory in a higher level, then you should move up to this level then down to the file.
<?php include('../../path/to/file.php'); ?>
where ../../
is going up 2 levels, you can set it to as many levels you want to go up.
If you want to get the output from an external php file in a variable, you can get it using the PHP buffering functions:
ob_start();
include("/home/xxxxxxx/public_html/xxxxxxxa.php");
$output_from_php_file = ob_get_contents();
ob_end_clean();
Then you can append $output_from_php_file
to your $output
variable wherever you want.
精彩评论