简体   繁体   中英

How To Include Only Part Of A File With PHP

is there a way to include only part of a file using the PHP's include function? Say inside the document is normal html and the only parts i want are those marked with div id="content" how would i include just the "content" portion?

is not possible such thing, i suggest you to use template files

the with with templates is something like this

html.tpl.php:

<html>
   <head>
      <?php echo $html_headers; ?>
   </head>
   <body>
   <?php echo print_content_div(); ?>
   </body>
</html>

my_php_page.php:

 $html_headers='your headers';
 include 'content_div.php';
 include 'html.tpl.php';

content_div.php:

<?php
function print_content_div(){
   echo "<div id='content'>Your content here</div>";
}

this way you can write huge pages without repeating your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM