Jump to content

Recommended Posts

Hi.

 

I'm new to php and i thought i was being clever and saving myself hassle by using includes for the design of my website. using an include for each section, header, subheader, body and footer.

 

In the pages which use the include and call the design pages (page.php), i have the variables which are added into the designs.

 

For instance, my body_design.php has a variable $bodycontent which loads the content from the variable defined in page.php

 

This all works really well when all im putting in the variable definition is html code and text. It doesn't work if i try and put other php defined variables.

 

I'd like my bodycontent section to show 2 variables, also defined in page.php $var1 and $var2 but i dont know how.

 

I assumed that i would use

 

$bodycontent='<?php echo "$var1 and $var2"; ?>'

 

However this doesn't work (which i assume for anyone with experience is obvious).

 

Can anyone explain how i would do this. I've tried to simplify my situation as the whole thing is quite complex, hope someone can understand what im trying to do.

 

Thanks,

 

StuButler

 

 

Link to comment
https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/
Share on other sites

Sorry that should have read

 

$bodycontent='<?php echo "$var1" and "$var2"; ?>'

 

using the . just give me a blank space, no actual variables

 

I've added just an echo outside of the designed section and they come up fine so i know the variables are working correctly.

 

Thanks,

 

StuButler

 

I'm assuming your page looks like:

 

<?php
$bodycontent='<?php echo "$var1" and "$var2"; ?>';
?>

 

 

My question is.... Why would you reopen PHP?

 

You would just do

 

$bodycontent = $var1 . $var2;

 

Or, if you want some normal text too,

 

$bodycontent = 'This is normal text.... if you put $var here, it will put out \'$var\'.... ' . $var1 . 'this is some more text' . $var2 . "if you use double quotes and put $var1, then $var1 will be replaced with the value of $var1" . $var3 . "If you're wondering why I put \' in the first part, it's because ' has to be escaped when you're using single quotes, or PHP will parse it as if you're ending that string.";

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.