[英]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? 有没有一种方法可以使用PHP的include函数仅包含文件的一部分? 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?
说在文档内部是普通的html,我只需要标有div id =“ content”的那些部分,我将如何仅包括“ content”部分?
is not possible such thing, i suggest you to use template files 这是不可能的,我建议您使用模板文件
the with with templates is something like this with与模板是这样的
html.tpl.php: html.tpl.php:
<html>
<head>
<?php echo $html_headers; ?>
</head>
<body>
<?php echo print_content_div(); ?>
</body>
</html>
my_php_page.php: my_php_page.php:
$html_headers='your headers';
include 'content_div.php';
include 'html.tpl.php';
content_div.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 这样,您可以编写大型页面而无需重复代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.