PHP 短开放标签打印“1”

Sal*_*yon 1 php

当我使用 php 短开放标记用 html 编写 php 代码时,它每次都会打印 1 。

<?= include_once 'includes/footer.php';?>
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

Eri*_*Ven 5

因为它返回true。您需要include_once在没有短开放标签的情况下使用,如下所示:

<?php include_once 'includes/footer.php';?>
Run Code Online (Sandbox Code Playgroud)

当你写一个开放的短标签时,像这样;

<?= include_once 'includes/footer.php';?>
Run Code Online (Sandbox Code Playgroud)

你实际上是这样写的:

<?php echo include_once 'includes/footer.php';?>
Run Code Online (Sandbox Code Playgroud)

这会导致屏幕上显示“1”。