Question:
I need help with PHP include() echo and variables?
Kitty Juice
2009-10-17 18:33:39 UTC
I am having trouble taking a variable from my include and echoing it.
It's a nav bar that determines what css class to use based on the file name.

template.php:
$nav_bar =
"
Six answers:
Hunter
2009-10-17 19:00:00 UTC
template.php:


$nav_bar =

"
anonymous
2009-10-17 19:46:49 UTC
1) $nav_bar =

"
exch
2009-10-17 18:54:02 UTC
The php code is part of the string literal and will therefor be treated as such.



Try this:


$nav_bar = '
Codster
2009-10-17 20:26:38 UTC
Well, I put it on my server and it executed properly, however, I believe that you do not need to put an opening php tag in your variable. i.e. "
>" should not have because you already are using php to echo the variable.
quayman0001
2009-10-17 19:19:42 UTC
Simple answer!



When you echo a variable, don't use double quotes. Saying echo "$nav_bar" will give you output of "$nav_bar"



Change that line to:



echo $nav_bar;



and it should work!
anonymous
2009-10-17 18:37:45 UTC
i had this problem and i found a very simple fix after doing hours of research. so i went to command prompt, stood up infront of my computer and started dancing infront of it then it worked


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...