StuButler Posted May 22, 2007 Share Posted May 22, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/ Share on other sites More sharing options...
spode Posted May 22, 2007 Share Posted May 22, 2007 Concentation. $bodycontent='<?php echo "$var1 . $var2"; ?>' Quote Link to comment https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/#findComment-259429 Share on other sites More sharing options...
StuButler Posted May 22, 2007 Author Share Posted May 22, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/#findComment-259436 Share on other sites More sharing options...
spode Posted May 22, 2007 Share Posted May 22, 2007 oh yeah, for got the "" Quote Link to comment https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/#findComment-259440 Share on other sites More sharing options...
StuButler Posted May 22, 2007 Author Share Posted May 22, 2007 still get a blank space. the page source from my browser is correct: <?php echo "$var1" . "$var2" ?> but it doesnt actually load the variables, just leaves them blank. StuButler Quote Link to comment https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/#findComment-259445 Share on other sites More sharing options...
StuButler Posted May 22, 2007 Author Share Posted May 22, 2007 I think its the echo tag that isnt working properly Can you not use echo tags inside variables? Thanks, StuButler Quote Link to comment https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/#findComment-259447 Share on other sites More sharing options...
spode Posted May 22, 2007 Share Posted May 22, 2007 No. I'm pretty sure you'd have to make a function. But I'm just an ewb soo ??? Quote Link to comment https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/#findComment-259448 Share on other sites More sharing options...
corbin Posted May 22, 2007 Share Posted May 22, 2007 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."; Quote Link to comment https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/#findComment-259454 Share on other sites More sharing options...
StuButler Posted May 23, 2007 Author Share Posted May 23, 2007 Thanks, it was indded the double quotations that i was missing. Thanks, StuButler Quote Link to comment https://forums.phpfreaks.com/topic/52579-solved-include-variable-problem/#findComment-259702 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.