PHP 将无法正确执行,仅显示为文本


PHP will not execute properly and only displays as text

我的整个PHP页面只显示为文本,没有执行PHP代码。这很奇怪,因为当我在test.php文件中使用<? phpinfo(); ?>进行测试时,我得到了一个成功的测试,它可以在我的Apache服务器上工作。但是,当我尝试做其他任何事情时。它仅显示为文本。

编辑:这是代码的链接。我不知道如何在这里发布它。帕斯宾

<?php
  // create short variable names
  $tireqty = $_POST['tireqty'];
  $oilqty = $_POST['oilqty'];
  $sparkqty = $_POST['sparkqty'];
  $find = $_POST['find'];
?>
<html>
<head>
  <title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
    echo "<p>Order processed at ".date('H:i, jS F Y')."</p>";
    echo "<p>Your order is as follows: </p>";
    $totalqty = 0;
    $totalqty = $tireqty + $oilqty + $sparkqty;
    echo "Items ordered: ".$totalqty."<br />";

    if ($totalqty == 0) {
      echo "You did not order anything on the previous page!<br />";
    } else {
      if ($tireqty > 0) {
        echo $tireqty." tires<br />";
      }
      if ($oilqty > 0) {
        echo $oilqty." bottles of oil<br />";
      }
      if ($sparkqty > 0) {
        echo $sparkqty." spark plugs<br />";
      }
    }

    $totalamount = 0.00;
    define('TIREPRICE', 100);
    define('OILPRICE', 10);
    define('SPARKPRICE', 4);
    $totalamount = $tireqty * TIREPRICE
                 + $oilqty * OILPRICE
                 + $sparkqty * SPARKPRICE;
    echo "Subtotal: $".number_format($totalamount,2)."<br />";
    $taxrate = 0.10;  // local sales tax is 10%
    $totalamount = $totalamount * (1 + $taxrate);
    echo "Total including tax: $".number_format($totalamount,2)."<br />";
    if($find == "a") {
      echo "<p>Regular customer.</p>";
    } elseif($find == "b") {
      echo "<p>Customer referred by TV advert.</p>";
    } elseif($find == "c") {
      echo "<p>Customer referred by phone directory.</p>";
    } elseif($find == "d") {
      echo "<p>Customer referred by word of mouth.</p>";
    } else {
      echo "<p>We do not know how this customer found us.</p>";
    }
?>
</body>
</html>

我愿意下注 10 美元,test.php使用 <?php ,并且更改后的代码使用 <? ,而服务器不将其理解为开始标签,因为short_open_tags在 php.ini 中关闭。

很多书籍使用<?作为开放标签,而大多数服务器只支持长版本(<?php(。如果是这种情况,那么将所有简单的<?更改为<?php就可以了。

PHP 代码

仅在 1 种情况下公开:当 PHP 解释器未将其标识为 PHP 代码时。这可能仅由 2 个问题引起:

  • Apache(或其他http服务器(的错误配置,根本不处理php文件。
  • PHP
  • 文件中的打开标记错误,因此 PHP 不知道代码何时开始。

如果文件是 *.php,如果 Apache 打开了通过 PHP 解释器提供 *.php 文件,如果使用标准开放标签或 PHP 配置为使用其他类型的已使用标签,并且如果您通过浏览器访问此 PHP 文件,PHP 在任何情况下都不会公开此代码。