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