m-code Posted June 23, 2007 Share Posted June 23, 2007 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 https://forums.phpfreaks.com/topic/56868-solved-including-php-file-with-str_replace-ereg_replace/ Share on other sites More sharing options...
m-code Posted June 24, 2007 Author Share Posted June 24, 2007 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 https://forums.phpfreaks.com/topic/56868-solved-including-php-file-with-str_replace-ereg_replace/#findComment-281144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.