Jump to content

[SOLVED] including php file with str_replace / ereg_replace


m-code

Recommended Posts

I'm trying to include a php file at a certain point in my template.

Including works fine, just it doesn't place it at the right place where I want it to be.

The news.php file will be included up front and not at the desired place {content} where it should go to.

I tried str_replace instead of ereg_replace, but str_replace displayed only the news.php page and truncated the rest of the page.

 

main.php:

$row = file_get_contents("template.htm");
$row = ereg_replace("{login}",$login,$row);
$row = ereg_replace("{menu}",$menu,$row);
$row = ereg_replace("{content}",eval(file_get_contents("news.php")),$row);
print $row;

 

template.htm:

<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="200"> </td>
    <td width="407" id="menu">{menu}</td>
  </tr>
  <tr>
    <td id="login">{login}</td>
    <td id="content">{content}</td>
  </tr>
</table>

 

I'd appreciate every help, I browsed thru the forum but could only find one closeley related post to my problem, but it didn't really help me any further as I was before.

 

thx ^_^

Link to comment
Share on other sites

For who ever needs this solution too. I found a way of how to do it.

Basically you need to use ob-handlers. What I did is create a function and return the eval'd code into a variable to be able to replace it later.

 

function strInclude($content){
ob_start();
eval($content);
$content = ob_get_contents();
ob_end_clean();
return $content;
}

$content = file_get_contents("file.php");
$content = strInclude($content);

 

found help @ php.net browsing thru the eval posts

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.