为什么PHP标记不能在html文件中工作? [英] Why php tag is not working in html file?

查看:103
本文介绍了为什么PHP标记不能在html文件中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  global $ name; 
$ name =;

现在在html表单中我有:

 < form name =registeraction =register.phpmethod =postclass =smart-green> 


< h1>联络表格
< span>登记表格< / span>
< / h1>
< label>
< span>用户名:< / span>
< input id =nametype =textname =usernamevalue =<?php echo $ name;?> placeholder =输入您的用户名maxlength =20/>
< / label>
< / form>

但是输出是<?php echo $ name; ?> 而不是空的!任何想法如何解决这个问题?

解决方案

您的web服务器将按原样服务于HTML页面。它只会尽可能地解析HTML。如果您使用PHP扩展名重命名页面,则Web服务器将使用PHP解释器对其进行解析,这就是解释PHP的时候。正如Fred在评论中指出的那样,您可以告诉Apache将HTML视为PHP。

I have a register.php file and I have defined $name="" inside that file

global $name;
$name = "";

and now in the html form I have:

    <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>

But the output is <?php echo $name; ?> instead of empty! Any idea of how I can fix this?

解决方案

Your web server will server the HTML page as is. It will only parse the HTML as best as it can. If you rename your page with a PHP extension, the web server will parse it using the PHP interpreter and that is when PHP will be interpreted. Also as Fred points out in the comments you can tell Apache to treat HTML as PHP.

这篇关于为什么PHP标记不能在html文件中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆