Jump to content

Simple include problem


Nolandis

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/252372-simple-include-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.