michaellunsford Posted January 24, 2007 Share Posted January 24, 2007 I've been using str_replace to include html files with file_get_contents(). Well, now the challenge is to [color=green]include[/color] a PHP file.[code]<?phpecho str_replace($string,"|contact_form|",file_get_contents("contact_form.html"));?>[/code]if I use file_get_contents(), it just displays the raw PHP script. If I eval() it, I get errors (unexpected '$' on line 1 -- but there is no $ on line 1?) Link to comment https://forums.phpfreaks.com/topic/35536-include-a-file-in-str_replace/ Share on other sites More sharing options...
Carterhost Posted January 24, 2007 Share Posted January 24, 2007 You could use include?[code] <?phpinclude ("footer.php"); ?>[/code] Link to comment https://forums.phpfreaks.com/topic/35536-include-a-file-in-str_replace/#findComment-168270 Share on other sites More sharing options...
michaellunsford Posted January 24, 2007 Author Share Posted January 24, 2007 can't use include inside str_replace. "include" is treated as a variable instead of a command. Link to comment https://forums.phpfreaks.com/topic/35536-include-a-file-in-str_replace/#findComment-168274 Share on other sites More sharing options...
Carterhost Posted January 24, 2007 Share Posted January 24, 2007 Eek, Should have engaged brain first!Apologies. Link to comment https://forums.phpfreaks.com/topic/35536-include-a-file-in-str_replace/#findComment-168284 Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 Can you post the content of the file you're trying to include? You'll need to use eval() on it, but since that's putting out an error, let's see the code. Link to comment https://forums.phpfreaks.com/topic/35536-include-a-file-in-str_replace/#findComment-168287 Share on other sites More sharing options...
michaellunsford Posted January 24, 2007 Author Share Posted January 24, 2007 Finally managed to figure it out.The destination PHP file was including another file that generated a cookie. Seems that eval() doesn't know how to say "headers already sent," so I guess it gave me that weird "unexpected '$' on line 1" error ??? Link to comment https://forums.phpfreaks.com/topic/35536-include-a-file-in-str_replace/#findComment-168305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.