通过php将html添加到新创建的页面中


add html to a newly created page through php

我正在处理一个项目,我正在通过php创建一个页面,但创建的页面是空白的,我的意思是没有html,但我需要做的是在该页面中也有html

这是代码的帮助下,我正在创建页面

     $ourFileName = $title.".php";
     $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
     fclose($ourFileHandle);

但是当页面创建时,我希望这个html也在那个页面中

     <div class="content">
 <form action="" class="valid" method="post" enctype="multipart/form-data">
    <div class="row">
        <label>Title</label>
        <div class="right"><input type="text" name="title" value="<?php echo $row['title'];?>"
    /></div>
      </div>
                        <div class="row">
            <label>Link</label>
            <div class="right"><input type="text" name="link" value="http://localhost/admin/your page name"
    /></div>
      </div>
        <div class="row">
        <label></label>
            <div class="right">
            <button type="submit"><span>Enter menu item</span></button>
                                <input type="hidden" name="hidden" />
                            </div>
                        </div>
                    </form>
                </div>

如果您想组合php和html,您可以将php封装到html站点中,例如:

<html>
<title>...</title>
<?php
echo 'this comes from php';
?>
<p>Some HTML Text</p>
<?php
echo '<b>You could also add some html tags here</b>';
?>
</html>

确保将其保存为.php,以便由php进程执行。

如果你想从php创建html文件,你必须使用这样的东西:

<?php
file_put_contents('somefile.html', '<html>...</html>');
?>

如果我正确理解问题,您使用的是:

 $ourFileName = $title.".php";
 $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
 fclose($ourFileHandle);

添加包含页面中显示的代码的文件。

这是行不通的。除了打开和关闭文件而不进行任何操作之外,所包含的文件/html还包含php。

如果你想执行该文件中的php,你需要包含该文件,而不是打开并写入它:

 $ourFileName = $title.".php";
 include $ourFileName;

使用include语句:

http://php.net/manual/en/function.include.php

当您包含与html组合的标签时,请记住使用php扩展,以避免忽略来自Web服务器的php代码