如何从示例页面创建一个页面,用用户输入替换某些文本



我想做一个页面,里面有一个表单

    <form class="col s12" method="POST" action="addtask.php">
  <div class="row">
    <div class="input-field col s6">
      <input placeholder="Username" id="user" type="text" class="validate">
      <label for="user">Username</label>
    </div>
  <div class="row">
    <div class="input-field col s12">
      <input placeholder="SkyMaker" id="title" type="text" class="validate">
      <label for="title">Title</label>
       <div class="row">
    <div class="input-field col s12">
      <input placeholder="This makes a sky" id="desc" type="text" class="validate">
      <label for="desc">Description</label>
  <div class="row">
    <div class="input-field col s12">
      <input id="dlink" placeholder="http://example.com" type="url" class="validate">
      <label for="dlink">Download LInk</label>
    </div>
  </div>
<button class="btn waves-effect waves-light" type="submit"         name="action">submit
<i class="material-icons right">send</i>

    </div>
  </div>
</form>

Addtask.php包含:

    <?php
    if(isset($_GET["type"]) && isset($_GET["message"]) &&        isset($_GET["line"]) && isset($_GET["file"])) {
if(is_numeric($_GET["line"])) {
    if($_GET["type"] !== "" && $_GET["message"] !== "" && $_GET["file"] !=="") {
        $id = 0;
        while(file_exists($id . ".html")) {
            $id++;
        }
        $html = file_get_contents("example.html");
        $html = str_ireplace("resc_title", $_GET["title"], $html);
        $html = str_ireplace("resc_user", $_GET["user"], $html);
        $html = str_ireplace("resc_desc", $_GET["desc"], $html);
        $html = str_ireplace("resc_dlink", $_GET["dlink"], $html);
        file_put_contents($id . ".html", $html);
        echo "http://example.com" . $id . ".html";
    }
}

但是,当我提交表单时,它带我到一个空白页(addtask.php)。example.html包含一个模板,与resc_title, resc_user和所有其他的在某些地方,我做错了什么?

你的输入都错过了name属性,所以PHP不知道你的表单字段,你也可以将str_ireplace组合成一个使用数组搜索和替换关键字

最新更新