【问题标题】:php syntax error, unexpected $end line 36 [closed]php 语法错误,意外的 $end 第 36 行 [关闭]
【发布时间】:2013-04-05 17:34:43
【问题描述】:

好的,原来的建议似乎奏效了。他们没有像以前那样的错误代码。但现在它告诉我它的结局并不好。我尝试了多种语法,但似乎没有任何效果。和一个 IF 把它拿走......甚至删除 <? end if ?> 或诸如此类的东西。有什么想法吗?

<?php
$correct = true;
if ($_GET["firstname"] == "")
    $correct = false;
if (preg_match("/^.+@\w+\.\w{2,4}$/", $_GET["email"]))
    $correct = false;

$to = "sample@domain.com";
$subject = "Application request";

$message = "A new request has come in!\n\n";
$message .= $_GET["firstname"];
$message .= $_GET["lastname"];"\n";
$message .= $_GET["email"];"\n";
$message .= $_GET["phone"];"\n";
$message .= $_GET["dropdown"];"\n";
$message .= $_GET["address"];"\n";
$message .= $_GET["dropdown2"];"\n";
$message .= $_GET["textarea"];"\n";

?>
<html>
<head>
    <title>something funky
    </title>
</head>
<body>
<?php if ($correct): ?>
Thank you for applying. We will get back to you shortly.<br>
<?php else: ?>
Please complete the form.
<?php end ?>

</body>
</html>

【问题讨论】:

标签: php


【解决方案1】:

改变

<?php end ?>

通过

<?php endif; ?>

【讨论】:

    【解决方案2】:

    您的代码:

    $message .= $_GET["lastname"];"\n";
    

    你必须用点字符替换分号:

    $message .= $_GET["lastname"] . "\n";
    

    【讨论】:

      【解决方案3】:

      改变

      <?php if ($correct): ?>
      Thank you for applying. We will get back to you shortly.<br>
      <?php else: ?>
      Please complete the form.
      <?php end ?>
      

      到

      if($correct){
      // thank you for ...
      }
      
      else{
      // please complete
      }
      

      【讨论】:

      • 我意识到他的语法是可以接受的,我只是更喜欢这种方式:)
      • @FelixKling 这就是为什么他们允许两个版本;)
      • 虽然应该是endif;
      • @DamienPirsy 语法完全不同...
      【解决方案4】:

      你错过了endif。试试这个,

       <?php if ($correct): ?>
          Thank you for applying. We will get back to you shortly.<br>
          <?php else: ?>
          Please complete the form.
          <?php endif; ?>
      

      【讨论】:

      • 应该是endif 而不是end if。
      • @AlexHowansky 意识到并纠正了它。
      • 您仍然缺少 ;在 endif 的末尾
      • @DavidBélanger 对自己感觉不好。感谢您纠正我。
      • @David:AFIK,在这种情况下分号是可选的(我并不是说添加它不好,但它不是必需)。
      【解决方案5】:

      所以你可以使用它:

      <body>
      <?php if ($correct) { ?>
      Thank you for applying. We will get back to you shortly.<br>
      <?php } else { ?>
      Please complete the form.
      <?php } ?>
      </body>
      

      虽然不整洁,但效果很好

      你也可以这样写

      <body>
      <?php
      if ($correct) echo "Thank you for applying. We will get back to you shortly.<br>";
      else echo "Please complete the form.";
      ?>
      </body>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-09
        • 2012-05-16
        • 2014-12-18
        • 1970-01-01
        • 2012-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多