Ok, I can’t come to grips with this ob_start and ob_end_clean code…
Basically, I am trying to output PHP code within a page section.
Here is my source code:
$content = trim(html_entity_decode($context['page_data']['body'], ENT_QUOTES, $context['character_set']));
$content = trim($content, '<?php');
$content = trim($content, '?>');
function dream_error_handler($output)
{
$error = error_get_last();
$output = "";
if (!empty($error))
foreach ($error as $info => $string)
if ($info == 'message')
$output .= $string;
return $output;
}
ob_start('dream_error_handler');
eval($content);
$code = ob_get_contents();
ob_end_clean();
$context['page_data']['body'] = $code;
Now, in the template function, I am using this:
global $context;
echo '
<div class="cat_bar">
<h3 class="catbg">
', $context['page_data']['title'], '
</h3>
</div>
<span class="upperframe"><span></span></span>
<div class="roundframe">
', $context['page_data']['body'], '
</div>
<span class="lowerframe"><span><!-- // --></span></span>
';
So why am I getting this error message?
HTTP Error 500 (Internal Server
Error): An unexpected condition was
encountered while the server was
attempting to fulfill the request.
What am I doing wrong here? The $context[‘page_data’][‘body’] has valid PHP code, a simple echo 'Hello World'; but it gives me this 500 Internal Server Error. Why?
PHP’s
eval()shouldn’t be called for a string containing<?php ?>as it is assumed that the contents of the string itself is pure PHP code. So you should be able to remove the twotrim()calls you’re making in addition to using @Boldewyn’s suggestion.