0

所以,昨天我的代码非常适合我的网站......直到我意识到文档中没有人(1)出现!!!我已经搜索了整个代码,似乎没有任何问题!

我不知道这是否是 PHP (5.3) 中的错误,还是什么......它必须得到修复!

回顾:所有的(1)将因未知原因被删除)

我的代码在这里:

  echo "Please wait while we submit your recipe...";

  //getting form data
  $thedate = Date("d-m-Y_H:i:s");
  $title = $_POST['Title'];
  $description = $_POST['Descript'];
  $ingredients = $_POST['Ingredients'];
  $instructions =$_POST['Instructions'];
  $notes = $_POST['Notes'];
  $name = $_POST['Name'];

  //replacement for extra characters
  $title = str_replace("\'" && "\"", "" , $title);
  $description = str_replace("\'" && "\"", "" , $description);
  $ingredients = str_replace("\'" && "\"", "" , $ingredients);
  $instructions = str_replace("\'" && "\"", "" , $instructions);
  $notes = str_replace("\'" && "\"", "" , $notes);
  $name = str_replace("\'" && "\"", "" , $name);
  $title = str_replace("\\", "" , $title);
  $the_recipe_url="RecibaseWaitingList/".$thedate."--".$title.".txt";
  $the_recipe_url = str_replace("'", "" , $the_recipe_url);
  $the_recipe_url = str_replace("\"", "" , $the_recipe_url);
  $the_recipe_url = str_replace("?", "" , $the_recipe_url);
  $the_recipe_url = str_replace(chr(10), "_", $the_recipe_url);

  //bugs show up before or after this 
  echo '...';

    //Checking to see if all required fields are filled
    if($title !== '')
    {
        if($ingredients !=='')
        {
            if($instructions !=='')
            {
                          //writing to the file
                          $writetothefile = fopen($the_recipe_url, 'c');
                          fwrite($writetothefile, $name." submitted this recipe on ".$thedate." \r\n \r\n "); 
                          fwrite($writetothefile, "Title: ".$title." \r\n ");
                          fwrite($writetothefile, $description." \r\n ");
                          fwrite($writetothefile, " \r\n ");
                          fwrite($writetothefile, "Ingredents:\r\n".$ingredients." \r\n");
                          fwrite($writetothefile, " \r\n ");
                          fwrite($writetothefile, "Instructions: \r\n ".$instructions." \r\n ");
                          fwrite($writetothefile, "\r\n ");
                          fwrite($writetothefile, "Notes: \r\n" . $notes . "\r\n \r\n ");
                          fwrite($writetothefile, "Thank you ".$name." for submitting this recipe! \r\n \r\n When you're done with the recipe, just click the back button.");
                          fclose($writetothefile);

                          //echo's for the user to see      
                          echo '<br />Your recibase recipe url is <a href="' . $the_recipe_url . '">' . $the_recipe_url . '</a>.';
                          echo "<br />";
                          echo "<br />";                      
                          echo "Thank you for being so generous with your time and entering your recipe. We hope you enjoy using the rest of the site!< br />"; 
                          echo "<br />";                
                          echo '<a href="http://recibase.musicsuper.org/input.php">Click Here</a> to enter in another recipe.<br />';
                          echo "...and we're done!";
             }else{echo "Go back, and enter the <b><i>Instructions</i></b> of your recipe please!".'<br><br><a href="javascript:history.go(-1);">'.'<--- Go Back</a>';}
          }else{echo "Go back, and enter the <b><i>Ingredients</i></b> in your recipe please!".'<br><br><a href="javascript:history.go(-1);">'.'<--- Go Back</a>';}
      }else{echo "Go back, and enter the <b><i>Title</i></b> of your recipe please!".'<br><br><a href="javascript:history.go(-1);">'.'<--- Go Back</a>';

是什么导致1的消失?为什么会这样?

任何想法将不胜感激。

如果您想通过示例配方查看此代码的产品,请访问此处:http ://recibase.musicsuper.org/AllOfYourRecipes/RecibaseWaitingList/15-02-2013_13:38:17--Deer%20Liver% 20Pate.txt

4

3 回答 3

2

&&是一个逻辑运算符。

$title = str_replace("\'" && "\"", "" , $title);

如果您将&&两个字符串评估为 (boolean) true,则结果将为true. 转换回字符串将是1. 所以实际上你正在删除所有1s.

于 2013-02-15T22:50:59.633 回答
1

你的问题是str_replace,尤其是"\'" && "\""。这个语句相当于1,所以你str_replace是有效的str_replace(1, "" , $title);

你会想要使用一个数组,所以代码将是

str_replace(array("\'", "\""), "" , $title);

正如您所期望的那样,这将用空字符串替换所有出现的数组元素。

于 2013-02-15T22:51:13.747 回答
0

我可能发现了你的问题:

你不能这样使用这个函数:

str_replace("\'" && "\"", "" , $ingredients);

("\'" && "\"")被评估TRUE为布尔值和"1"字符串。

将数组传递给函数:

str_replace(array("\'", "\""), "" , $ingredients);
于 2013-02-15T22:57:12.063 回答