2016-08-24 57 views
0

我刚刚开始学习PHP,所以最近我只是跟着一个教程,直到遇到此错误。php - 由于php错误而没有显示任何内容

与PHP只是它的方式,即使它在教程视频中完美地工作,页面也不显示任何内容。

我还发现了很多类似于我的问题,但我无法真正将它应用于我的代码。

无论如何,我要切入正题

这是代码

if ( !isset($_POST['fix_submit'])) { 

     $clickbait = strtolower $_POST["clickbait_headline"]; 

     // grab value from textarea in $_POST collection 
     // make all letters lowercase using strtolower() function 
     // store in a variable 

     $fake = array(
       "doctors", 
       "scientists", 
       "shocked me", 
       "won't believe", 
       "will never believe", 
       "hate" 
      ); 
     $replaceFake = array(
       "so-called doctors", 
       "so-called scientists", 
       "was like the others", 
       "will find normal", 
       "won't be surprised", 
       "aren't threatened by" 
      ); 

     $honestHeadline = str_replace ($fake, $replaceFake, $clickbait ); 

    } 

整个误差是于第一线因为每当我删除的页面显示HTML但显然PHP不会工作。


编辑

修复那些语法错误后,固定无事的部分显示这样的帮助表示感谢。

现在它说

未定义指数:clickbait_headline上线8

,当我点击提交按钮没有任何反应 无论如何,这是整个代码

<?php 

    define ("TITLE", "Honest Click Bait Headline"); 


    if ( !isset( $_POST['fix_submit'])) { 

     $clickBait = strtolower ($_POST["clickbait_headline"]); 

     // grab value from textarea in $_POST collection 
     // make all letters lowercase using strtolower() function 
     // store in a variable 

     $fake = array(
       "doctors", 
       "scientists", 
       "shocked me", 
       "won't believe", 
       "will never believe", 
       "hate", 
       "hack", 
       "simple" 

      ); 
     $replaceFake = array(
       "so-called doctors", 
       "so-called scientists", 
       "was like the others", 
       "will find normal", 
       "won't be surprised", 
       "aren't threatened by", 
       "common knowledge", 
       "well-known" 
      ); 

     $honestHeadline = str_replace ($fake, $replaceFake, $clickBait ); 
    } 
?> 

<!DOCTYPE html> 

<html> 

    <head> 

     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 



     <title><?php echo TITLE; ?></title> 


     <!--bootstrap CSS--> 
     <link href="bootstrap/css/bootstrap.css" rel="stylesheet"> 

     <!-- Custom styles --> 
     <link href="styles.css" rel="stylesheet"> 


    </head> 

    <body> 
     <div class="container"> 

      <h1><?php echo TITLE; ?></h1> 
      <p class="lead">hate click baits? Turn those annoying headlines into realistic and honest ones.</p> 
      <div class="row"> 
       <form class="col-sm-7 col-sm-offset-2" action="" method="post"> 
        <textarea class="form-control input-lg" name="clickbait_headline" rows="2" placeholder="Paste clickbait headline here"></textarea><br> 
        <button class="btn btn-primary btn-lg pull-right" type="submit" name="fix_submit">Make Honest!</button> 
       </form> 
      </div> 
      <?php if (!isset($_POST["fix_submit"])) { 

        echo "<strong class='text-danger'>Original Headline</strong> <h4>".ucwords($clickBait)."</h4><hr><br> "; // ucwords() to uppercase first letter in every word 

        echo "<strong class='text-success'>Honest Headline</strong> <h4>".ucwords($honestHeadline)."</h4>"; 

      } 
      ?> 

     </div> 

    </body> 

</html> 
+0

死亡白屏:错误检查\显示已关闭,打开它们以查看错误。在你的php页面的顶部添加:'ini_set('display_errors','On'); ini_set('html_errors',0); error_reporting(-1);' – 2016-08-24 00:36:25

+0

发布更多关于表格的代码 –

+0

'strtolower'是一个函数,使用括号。 '$ clickbait = strtolower($ _POST [“clickbait_headline”]);'投票结束为错字。 – chris85

回答

0

更换$clickbait = strtolower $_POST["clickbait_headline"];

$clickbait = strtolower($_POST["clickbait_headline"]);