roldahayes Posted December 17, 2009 Share Posted December 17, 2009 Hi the code below calls a menu at the top of my pages. My question is, can I assign $topnav to a PHP includes? I would like it to display menu.php in the space that $topNav is displayed on. I hope that all makes sense! $topNav = '<div id="topnav" class="topnav"> <a href="login.php" class="signin"><span>Sign in</span></a><a href="./register.php" class="register"><span>Register</span></a></div> <form method="post" id="signin" action="./index.php"> <label for="username">Username or email</label> <input id="username" name="username" value="" title="username" tabindex="4" type="text"> <p> <label for="password">Password</label> <input id="password" name="password" value="" title="password" tabindex="5" type="password"> </p> <p class="remember"> <input id="signin_submit" value="Sign in" tabindex="6" type="submit"> <input id="remember" name="remember_me" value="1" tabindex="7" type="checkbox"> <label for="remember">Remember me</label> </p> <p class="forgot"> <a href="./forgotten.php" id="resend_password_link">Forgot your password?</a> </p> <p class="forgot-username"> <a href="./forgotten.php" id="forgot_username_link" title="If you remember your password, try logging in with your email" href="#">Forgot your username?</a></p> </form> </fieldset> '; } Link to comment https://forums.phpfreaks.com/topic/185476-can-i-use-an-includes-to-call-this-menu/ Share on other sites More sharing options...
rajivgonsalves Posted December 17, 2009 Share Posted December 17, 2009 not really why not just echo $topNav would that not do ? Link to comment https://forums.phpfreaks.com/topic/185476-can-i-use-an-includes-to-call-this-menu/#findComment-979219 Share on other sites More sharing options...
roldahayes Posted December 17, 2009 Author Share Posted December 17, 2009 Actually, I might as well just use <?php include("menu.php"); ?> as there isnt really a lot to to $topNav Thanks for looking though! Link to comment https://forums.phpfreaks.com/topic/185476-can-i-use-an-includes-to-call-this-menu/#findComment-979227 Share on other sites More sharing options...
steveboj Posted December 17, 2009 Share Posted December 17, 2009 You really shouldn't have all that HTML inside a PHP variable - I'm surprised it actually works! You've got two options: 1. Put all that HTML inside a text file and simply include that text file wherever you want it to appear, e.g. include("menu_file.inc"); 2. Create a new PHP file, create a function inside that file called top_nav() to contain all that HTML, then include that file at the top of your pages and use the following code to call that function wherever you want it to appear, e.g. top_nav(); If you're not already familiar with PHP functions, you should read up about them. Personally I would create a function for this, but because that code doesn't include any PHP, it would probably be simpler for you to use the text file option. Link to comment https://forums.phpfreaks.com/topic/185476-can-i-use-an-includes-to-call-this-menu/#findComment-979229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.