Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将html与php结合_Php_Html - Fatal编程技术网

如何将html与php结合

如何将html与php结合,php,html,Php,Html,我正在尝试将php与html表单连接起来。当前我的代码如下所示: <? php $path = "books /"; $books = opendir ($path); while (($book = readdir ($books))! == false) { if (substr ($book, -4) === ".txt") { $filePath = $path. $book; // echo

我正在尝试将php与html表单连接起来。当前我的代码如下所示:

<? php

$path = "books /";
$books = opendir ($path);
while (($book = readdir ($books))! == false)
{
    if (substr ($book, -4) === ".txt")
    {
        $filePath = $path. $book;
        // echo $book;

        $readFile = fopen ($filePath, "r+") or die ("Permission error");
        $infoBook = fread ($readFile, filesize($filePath));
        echo $infoBook;
        echo "<br>";
        $writeInfo = fwrite ($readFile, filesize($filePath));
        fclose ($readFile);
    }
    
}
closedir ();

?>
<html>
    <head>
        <title> Books Form </title>
        <meta charset = "UTF-8">
        <meta name = "viewport" content = "width = device-width, initial-scale = 1.0">
        <script src = "jquery-3.6.0.js"> </script>
        <style>
            
        </style>
    </head>
    <body>
        <form method = "post" action="<? php $_SERVER ['PHP_SELF'];?>" id = "bookform">
            <label for = "books"> </label>
            <select name = "book" id = "books" form = "bookform">
                
                <option value = "blank"> </option>
                <option value = "Atlas_chmur.txt"> Cloud Atlas </option>
                <option value = "Dune.txt"> Dune </option>
            </select> <br> <br>
            <button style = "position: relative; left: 240px" type = "submit" form = "form" value = "<? php $readFile = fopen ($book," r + ");?>" name = "click" > Load </button> <br> <br>
            <textarea name = "info" rows = "30" cols = "100">
                <? php echo $infoBook?>
            </textarea> <br>
            <button type = "submit" form = "form" value = "Submit"> Save </button> <br>
        </form>
    </body>
</html>

书的形式

您可以像这样在PHP中完成它

<?php for ($x = 0; $x <= 10; $x++): ?>
  <option value="<?= $x ?>"><?= $x ?></option>
<?php endfor; ?> 


当你在
$
符号和变量名之间留一个空格时,你不会出错吗?你对这段代码的确切问题是什么?这甚至可以在没有语法错误的情况下工作吗?请检查这个问题,它有您的问题的所有答案[PHP如何与HTML交互,反之亦然?])(),请将这一行添加到您的代码
ini_集('display_errors',1);ini设置(“显示启动错误”,1)您的php脚本有很多语法错误,可以显示添加这行代码code@Kasia13130“在文章中插入代码时,我将其格式化为怪异”-然后编辑您的问题并更正,请。什么是“它”?请在你的答案中添加一些解释,以便其他人可以从中学习。还有,给定的代码是如何工作的?在下拉列表中有11个元素,名称不同,但值相等,这有什么好的理由吗?这只是一个如何将HTML与PHP结合的示例。这就是他要求的。