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

时间:2012-05-21 22:04:39

标签: php

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

编辑:这是代码的链接。我无法弄清楚如何在这里发布。 Pastebin

<?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>

1 个答案:

答案 0 :(得分:5)

我愿意打赌test.php使用<?php的10美元,更改后的代码使用<?,而服务器不会将其理解为开始标记{{1}在php.ini中关闭。

许多书籍使用short_open_tags作为开放标记,而大多数服务器仅支持长版本(<?)。如果是这种情况,那么将所有简单的<?php更改为<?都可以解决问题。

PHP代码仅在以下情况下公开:当PHP解释器未将其识别为PHP代码时。这可能只有两个问题引起:

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

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