Nolandis Posted December 3, 2011 Share Posted December 3, 2011 Hello, I have a simple issue with a code that uses includes. What I want to do is to include a bit of php code I made to my main pages so I don't have to edit each file that will contain the same included code. The problem with that included code is that contains variables that only the main files would know. Let me show you basically what I'm talking about. mainfile1.php <?php $cat = "meow"; include "content.php"; ?> mainfile2.php <?php $cat = "mew"; include "content.php"; ?> (mainfile3.php and so on...) content.php echo '<center>My cat said '.$cat.' today!</center>'; I was expecting to see: My cat said meow today! and My cat said mew today! But when I loaded both pages it rendered like this: My cat said '.$cat.' today! HTML works properly but the variables are ignored and displayed as plain text. What I need to do so those variables don't get ignored? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/252372-simple-include-problem/ Share on other sites More sharing options...
Errant_Shadow Posted December 3, 2011 Share Posted December 3, 2011 Just to make sure, on content.php, there are the <?PHP ?> tags? <?php echo '<center>My cat said '. $cat .' today!</center>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/252372-simple-include-problem/#findComment-1293848 Share on other sites More sharing options...
Nolandis Posted December 3, 2011 Author Share Posted December 3, 2011 I thought it wasn't necessary as it was going to be included and I was thinking it would read it like <?php <?php ?> ?> but NO I was totally wrong, my bad. You, sir, solved my two-hour headache in less than ten minutes. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/252372-simple-include-problem/#findComment-1293853 Share on other sites More sharing options...
Errant_Shadow Posted December 3, 2011 Share Posted December 3, 2011 The worst problems tend to have the easiest fixes *nods* Be sure to mark as solved and happy coding. Quote Link to comment https://forums.phpfreaks.com/topic/252372-simple-include-problem/#findComment-1293858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.