php代码替换所有1';在写入txt文档时,它将不包含任何内容
所以,昨天我的代码非常适合我的网站。。。直到我意识到没有人(1)出现在文档中!!!我已经搜索了整个代码,似乎没有任何错误 我不知道这是不是PHP(5.3)中的一个bug,还是什么。。。。只需要把它修好 重述:所有的(1)将从未知原因中删除) 我的代码在这里:php代码替换所有1';在写入txt文档时,它将不包含任何内容,php,text-files,Php,Text Files,所以,昨天我的代码非常适合我的网站。。。直到我意识到没有人(1)出现在文档中!!!我已经搜索了整个代码,似乎没有任何错误 我不知道这是不是PHP(5.3)中的一个bug,还是什么。。。。只需要把它修好 重述:所有的(1)将从未知原因中删除) 我的代码在这里: echo "Please wait while we submit your recipe..."; //getting form data $thedate = Date("d-m-Y_H:i:s"); $title =
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>';
echo“请稍候,我们正在提交您的配方…”;
//获取表单数据
$thedate=日期(“d-m-Y:i:s”);
$title=$_POST['title'];
$description=$_POST['Descript'];
$配料=$_POST[“配料”];
$instructions=$_POST['instructions'];
$notes=$_POST['notes'];
$name=$_POST['name'];
//替换额外字符
$title=stru替换(“\”&&“\”,“,$title);
$description=str\u replace(“\”&&“\”,“,”,$description);
$Components=str_替换(“\”&&“\”,“,”,$Components);
$instructions=str\u replace(“\”&&“\”,“,”,$instructions);
$notes=STRU替换(“\”&&“\”,“,$notes);
$name=stru替换(“\”&&“\”,“,$name);
$title=str\u替换(“\\”、“”、$title);
$the_recipe\u url=“RecibaseWaitingList/”$thedate。”——“$title.”.txt”;
$the_recipe_url=str_replace(“,”,$the_recipe_url);
$theu recipe\u url=str\u replace(“\”,“,$theu recipe\u url”);
$the_recipe_url=str_replace(“?”,“”,$the_recipe_url);
$the_recipe_url=str_replace(chr(10),“uu”,“the_recipe_url”);
//在此之前或之后会出现bug
回声“…”;
//检查是否已填写所有必填字段
如果($title!='')
{
如果($成分!='')
{
如果($说明!='')
{
//写入文件
$writetothefile=fopen('c');
fwrite($writetothefile,$name.”于“$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”。$components.\r\n”);
fwrite($writetothefile,“\r\n”);
fwrite($writetothefile,“指令:\r\n”。$Instructions.\r\n”);
fwrite($writetothefile,“\r\n”);
fwrite($writetothefile,“Notes:\r\n”。$Notes.\r\n\r\n”);
fwrite($writetothefile,“谢谢”。$name.”用于提交此配方!\r\n\r\n完成配方后,只需单击“上一步”按钮即可);
fclose($writetothefile);
//回音供用户查看
echo“
您的recibase配方url为”;
回声“
”;
回声“
”;
echo“感谢您如此慷慨地投入您的时间并输入您的食谱。我们希望您喜欢使用网站的其余部分!
”;
回声“
”;
echo“输入另一个配方。
”;
echo“…我们完成了!”;
}否则{echo“返回,请输入配方说明!”。
&&
是一个逻辑运算符
$title=str\u replace(“\”&&“\”,“,$title);
如果您&
两个字符串的计算结果为(布尔值)true
,则结果将为true
。转换回字符串的值将为1
。因此,实际上您删除了所有1
。&
是一个逻辑运算符
$title=str\u replace(“\”&&“\”,“,$title);
如果您&
两个字符串的计算结果为(布尔值)true
,结果将为true
。转换回字符串的值将为1
。因此实际上您正在删除所有1
字符串。您的问题是str\u replace
,尤其是“\'”和“\”
。此语句相当于1
,因此您的str_replace
实际上是str_replace(1,“,$title);
您将希望使用数组,因此代码将是
str_replace(array("\'", "\""), "" , $title);
这将用空字符串替换数组中所有出现的元素,正如您所希望的那样。您的问题是str\u replace
,特别是“\”&&&&“
。此语句相当于1
,因此您的str\u replace
实际上是str\u replace(1,“,$title);
您将希望使用数组,因此代码将是
str_replace(array("\'", "\""), "" , $title);
这将用空字符串替换数组中所有出现的元素,正如您所希望的那样。我可能发现了您的问题:
您不能这样使用此功能:
str_replace("\'" && "\"", "" , $ingredients);
(“\”&&&“\”)
作为布尔值计算为TRUE
,作为字符串计算为“1”
将数组传递给函数:
str_replace(array("\'", "\""), "" , $ingredients);
我可能发现了你的问题:
您不能这样使用此功能:
str_replace("\'" && "\"", "" , $ingredients);
(“\”&&&“\”)
作为布尔值计算为TRUE
,作为字符串计算为“1”
将数组传递给函数:
str_replace(array("\'", "\""), "" , $ingredients);
被审查的“\”&&&“\”,
应该做什么?你的意图是什么?被审查的“\”&&“\”“,
应该做什么?你的意图是什么?哦!我不知道发生了什么!我以为它正在取代两者!我会很快去改变它。谢谢你在这方面的帮助。哦!我不知道发生了什么!我以为它正在取代两者!我会很快去改变它。谢谢你在这方面的帮助。