为什么我的PHP脚本有一半是以文本的形式出现的?

为什么我的PHP脚本有一半是以文本的形式出现的?,php,Php,我在我的Linux环境(我不是在Windows上运行)上尝试了相同的脚本,它工作得非常完美。脚本的要点(尽管不相关)是打印出表的内容 脚本如下: table_contents.php <? $user="root"; $password=""; $database="newtest"; $con = mysqli_connect(localhost,$user,$password,$database); if (mysqli_connect_errno()) { echo "Fai

我在我的Linux环境(我不是在Windows上运行)上尝试了相同的脚本,它工作得非常完美。脚本的要点(尽管不相关)是打印出表的内容

脚本如下:

table_contents.php

<?
$user="root";
$password="";
$database="newtest";
$con = mysqli_connect(localhost,$user,$password,$database);
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$query="SELECT * FROM contacts";
$result = mysqli_query($con,$query);

$num = mysqli_num_rows($result); // COUNT for FOR LOOP

echo '<table border=\'1\'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>'; //This is where it starts printing out everything.

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['first'] . "</td>";
  echo "<td>" . $row['last'] . "</td>";
  echo "</tr>";
  }

mysqli_close($con);
?>

而table_contents.php在我的浏览器上显示以下行:

Firstname Lastname';while($row=mysqli_fetch_数组($result)){echo”“;echo”“。$row['first']。;echo”“;}mysqli_close($con);?>

指示上面脚本中的注释行是一个点,在该点之后,将抛出所有要显示的内容


为什么会出现这种情况?我如何解决此问题?

您的服务器未配置为接受短标记(
您的服务器未配置为接受短标记)(
尝试使用
尝试使用
在使用
之前我遇到过问题如果你检查了HTML源代码,你会看到它实际上是以文本形式回显所有PHP脚本。我在使用
之前遇到过问题如果你检查了HTML源代码,你会看到它实际上是以文本形式回显所有PHP脚本。Shor如果php作为Apache模块运行,则可以在
php.ini
中使用
short\u open\u tag=On
启用t标记,或者在.htaccess文件中使用
php\u value short\u open\u tag 1
启用t标记。@CornFreek,但您确实不应该启用。@JasonMcCreary是的,我绝对建议使用完整标记。这里有一个更深入的讨论:我使用short-open标记,而不是我想这有什么问题。写视图代码的时候很棒。宁可使用短标记也不要使用Smarty。尽管,"自PHP 5.4.0以来,如果PHP作为Apache模块运行,则可以在
PHP.ini
中使用
Short\u open\u tag=On
启用短标记,或者在.htaccess文件中使用
PHP\u value Short\u open\u tag 1
启用短标记。@CornFreek,但您确实不应该。@JasonMcCreary是的,我绝对建议使用完整标记。下面是一个更深入的讨论:我使用短标记打开标签,不要认为它有任何问题。编写视图代码时非常棒。任何时候都可以使用短标签而不是Smarty。尽管“从PHP 5.4.0开始,