Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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
为什么php标记不能在html文件中工作?_Php_Html_Forms - Fatal编程技术网

为什么php标记不能在html文件中工作?

为什么php标记不能在html文件中工作?,php,html,forms,Php,Html,Forms,我有一个register.php文件,并且在该文件中定义了$name=”“ global $name; $name = ""; 现在在html表单中,我有: <form name="register" action="register.php" method="post" class="smart-green"> <h1>Contact Form <span>Registration Form</sp

我有一个register.php文件,并且在该文件中定义了$name=”“

global $name;
$name = "";
现在在html表单中,我有:

    <form name="register" action="register.php" method="post" class="smart-green">


        <h1>Contact Form
            <span>Registration Form</span>
        </h1>
        <label>
            <span>Username:</span>
            <input id="name" type="text" name="username" value ="<?php echo $name;?>" placeholder="Enter your user name" maxlength="20" />
        </label>
   </form>

联系方式
登记表
用户名:

将表单文件重命名为“.php”,以便解释php标记


在php文件中,您可以同时使用php和html代码,但不能反过来使用。

您的web服务器将按原样为html页面提供服务器。它将尽可能最好地解析HTML。如果使用PHP扩展名重命名页面,web服务器将使用PHP解释器对其进行解析,此时将解释PHP。正如Fred在评论中指出的,您可以告诉Apache将HTML视为PHP

没错, 要将文件识别为php,其扩展名应为ex-form.php
通过这种方式,可以执行它以提供输出

您不能在
.html
文件中运行
php
内容您的文件需要是
.php
才能拥有它execute@haxxxton这并不完全正确。可以指示Apache将
.html
文件视为PHP。@Fred ii-ah。。这是一个很好的观点。为我可能造成的任何困惑道歉没有问题o@haxxxton;-)他确实提到了它是一个.php文件,在前4个字中:P Edit:除非我读错了,这两个文件是分开的?我怎么能告诉Apache将HTML视为php?在
httpd.conf
中,您需要添加一行类似于:
AddHandler应用程序/x-httpd-php5.HTML