当我使用上面提到的(include,include_one,require_one(方法时,我会在我使用过的每个内容的末尾写上1。
看看:
PHP Code:
<!--Footer Section Starts Here-->
<?= require_once("elements/footer.php"); ?>
<!--Footer Section Ends Here-->
<!--Bottom CSS and JS Starts Here-->
<?= include_once("elements/bottom_css_and_js.php"); ?>
<!--Bottom CSS and JS Ends Here-->
Html Output
<div>
<div>
<p class="copyright">Copyright ©<script>document.write(new Date().getFullYear());</script> All rights reserved.</p>
</div>
<div>
<p class="copyright">This template is made with <i class="ion-ios-heart text-red" aria-hidden="true"></i> by <a href="http://localhost:8080/codeigniter4">Localhost</a></p>
</div>
</div>1
<!--Bottom CSS and JS Starts Here-->
<script src="http://localhost:8080/codeigniter4/public/assets/js/jquery.min.js"></script>
<script src="http://localhost:8080/codeigniter4/public/assets/js/popper.js"></script>
<script src="http://localhost:8080/codeigniter4/public/assets/bootstrap-footer-19/js/bootstrap.min.js"></script>
<script src="http://localhost:8080/codeigniter4/public/assets/js/main.js"></script>
</body>
</html>1
<!--Bottom CSS and JS Ends Here-->
这是对@sergiy T的评论(答案(和OP的评论的扩展,"不,它不起作用">
当前代码为
<!--Footer Section Starts Here-->
<?= require_once("elements/footer.php"); ?>
<!--Footer Section Ends Here-->
<!--Bottom CSS and JS Starts Here-->
<?= include_once("elements/bottom_css_and_js.php"); ?>
<!--Bottom CSS and JS Ends Here-->
由于使用<,您在哪里回显require_once和include_once等调用的结果=哪种是<?php echo。所以你会看到代码是";包括";以及函数调用的结果为1。
因此,您需要删除echo,因为执行require或include会将代码内联以执行/显示。
所以你需要把它改成…
<!--Footer Section Starts Here-->
<?php require_once("elements/footer.php"); ?>
<!--Footer Section Ends Here-->
<!--Bottom CSS and JS Starts Here-->
<?php include_once("elements/bottom_css_and_js.php"); ?>
<!--Bottom CSS and JS Ends Here-->
一如既往,最好阅读php.net 中的这些函数的作用