Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.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_Xml - Fatal编程技术网

在html页面中包含php文件

在html页面中包含php文件,php,html,xml,Php,Html,Xml,我正在使用XML和PHP填充web表单下拉框 我有一个html页面 <!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> <header> <h1>Title</h1> </header> <form> <di

我正在使用XML和PHP填充web表单下拉框

我有一个html页面

<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>

</head>

<body>
<header>
<h1>Title</h1>
</header>

    <form>
        <div id ="select xml">
            <?php include 'dropdown.php'; ?>
        </div>
    </form>
</body>

</html>

文件标题
标题
我希望包含以下PHP来生成包含XML文件名的实际框

<?php
//echo(substr(glob("xml/*.xml")[0],4));

echo  "<p>
      <label>Select list</label><br>
      <select id = \"selectxml\">
      <option value'0'>--Please Select--</option>";

        $count = count(glob("xml/*.xml"));
        $files = glob("xml/*.xml");
        for ($i = 0; $i < $count; $i++) {
            //echo(substr($files[$i],4));
            //echo "<br>";
        $filename = (substr($files[$i],4));
        echo "<option value=$i+1>$filename</option>";   
        }     

echo  "</select><br>
      <br>
      </p>";
?>

我知道PHP并不完美,但它可以工作


问题是,当我运行页面时,Include HTML不起作用-有什么想法吗?

将HTML页面从
.HTML
重命名为
.php

将扩展名更改为.php,您会没事的

当页面具有.html扩展名时,web服务器不会将其识别为PHP文件,并且不能在其中使用PHP代码。任何PHP代码都将作为纯文本处理

我的意思是当你把:

<?php echo "hello" ?>
它;这是不可能的,但通过函数,您可以做到:

$("#select-xml").load("dropdown.php");

默认情况下,服务器不会处理扩展名为.html.html的文件中的php代码,因为脚本是在web服务器处理页面后执行的。只有当dropdown.php包含html,而不是php
dropdown.php
结果是html元素,如
echo“$filename”,我做到了:)
echo
如果文件是.html,则对web服务器没有任何意义
hello
$("#select-xml").load("dropdown.php");