trackandfield Posted July 26, 2007 Share Posted July 26, 2007 I'm trying to include a page on another php page, and I'm not sure what function to use. Typically I would include a page with: <?php include 'filename.php'; ?> However, the larger page already begins with "<?php"... How do I include, or "call up", a PHP page in a PHP script? Thanks! Sean Quote Link to comment Share on other sites More sharing options...
noussh Posted July 26, 2007 Share Posted July 26, 2007 you can use include('config.php'); And you don't need to use php tag again for this function. noussh Quote Link to comment Share on other sites More sharing options...
per1os Posted July 26, 2007 Share Posted July 26, 2007 you can use include('config.php'); And you don't need to use php tag again for this function. noussh It is not required, but it is alright if you do it. The reason I would include them is incase someone wanders your site and finds filename.php, whoops all of your code is visible to everyone. The <?php and ?> will hide that code incase someone accidentally finds that page. Edit: Just re-read the question and found it confusing. The filename.php file should have the <?php tags. However to include a file inside a php file already, if you are working within the tags you do not need them again and it will throw a syntax error: //included.php <?php echo 'here'; ?> //wheretoinclude.php <?php echo 'Welcome we are '; include('included.php'); echo '!!!'; ?> The example above is how it should be done. Quote Link to comment Share on other sites More sharing options...
trackandfield Posted July 26, 2007 Author Share Posted July 26, 2007 I tried include('...'); , but the page ends up printing the actual code (see large print in upper right hand corner): http://www.jockandbuttons.com/ggh/news/news.php?action=detail&id=1185390632 To be more specific: I'm trying to include the PHP page within HTML code that is displayed by a PHP script. So within the actual PHP script beginning with <?php , some HTML will be displayed that tries to call up the other PHP page: echo " <div id='column_left_interior'> <?php include 'news.php'; ?> </div> However, it won't show up! Any thoughts? Thanks... Quote Link to comment Share on other sites More sharing options...
per1os Posted July 26, 2007 Share Posted July 26, 2007 How about you show us the page you are including and the page you want it to be included in's code. remember to use [ code ] tags (without spaces) Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 26, 2007 Share Posted July 26, 2007 you can break out of your echo statement at any time, include the file, and enter the echo statement again: echo " <div id='column_left_interior'>"; include 'news.php'; echo "</div> Quote Link to comment Share on other sites More sharing options...
nicelad_uk Posted July 26, 2007 Share Posted July 26, 2007 Sounds daft, but is your server PHP enabled? Some arent Quote Link to comment Share on other sites More sharing options...
trackandfield Posted July 26, 2007 Author Share Posted July 26, 2007 Breaking out of the echo statement does the trick. Thanks! Quote Link to comment 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.