当我使用上述(include、include_once、require、require_once)方法时,我会在使用它的每个内容的末尾写入 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 等的调用结果。因此,您将看到代码被“包含”,并且函数调用的结果为 1。
因此,您需要在执行 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 中的作用
关于php - codeigniter 4 在 include、include_once、require、require_once 之后返回 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67633488/