简单的 PHP 回显代码不起作用
这是我的 html 和 php 脚本:
<代码> <头> <标题>鲍勃的汽车零件 <正文>鲍勃的汽车配件
<表格宽度=100%> 这正在工作。"; ?>
为什么这个输出会出现一个 ; ?>。我希望它是“这有效”。仅有的。这是输出
鲍勃的汽车零件
鲍勃的汽车零件
这是有效的。”; ?>
我知道我在这里做错了什么,但无法弄清楚。提前致谢。
Here is my html with a php script:
<html> <head> <title>Bob's Auto Parts</title> </head> <body> <h1>Bob's Auto Parts</h1> <table width = 100% > <tr> <?php echo "<td>This is working.</td>"; ?> </tr> </table> </body> </html>
Why is the output of this appearing with a ; ?>. I want it to be 'This is working.' only. Here is the ouput
Bob's Auto Parts
Bob's Auto Parts
This is working.";
?>
I know I am doing something wrong here but not able to figure it out. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
确保您使用的是
而不是
简写,因为它可能在您的服务器上被禁用。这将导致 "; ?> 的输出,就像几个月前我在过渡到 PHP5 时发生的那样。
当 PHP 解析器未将其检测为 PHP 时,我只看到了这样的奇怪输出。请确保检查 PHP 是否按预期运行以及
标签是否被识别。
Make sure that you are using
<?php
and not<?
shorthand since that may be disabled on your server. This will cause the output of "; ?> as it happened to me a few months ago in a transition to PHP5.I've only seen the odd output like this when the PHP parser isn't detecting it as PHP. Make sure to check that PHP is functioning as expected and that the
<?php
tag is being recognized.这些(或更多)中的任何一个都可能是您的答案,为什么它不起作用
.php
吗?http://localhost/myfile.php
的操作?Any of these (or more) could be your answer why it is not working
.php
?http://localhost/myfile.php
在我的例子中(这是一个非常具体的例子),安装这个缺失的软件包(Ubuntu 14.04)就达到了目的:
对于使用 php7 的用户来说,安装该软件包:
之后,只需重新启动 apache:
就可以了。
In my case (which is a very specific case) installing this missing package (Ubuntu 14.04) did the trick:
for users working with php7 install the package:
After that, just restart apache:
And there you go.
当我发现我的错误时,我遇到了同样的问题:
我只是双击文件
file:///C:/Users 而不是正确的
。http://localhost/test.php
/.../htdocs/test.phpI had the same problem when I figured out my mistake:
Instead of correct
http://localhost/test.php
I just double clicked on the filefile:///C:/Users/.../htdocs/test.php
.文件正在以 Unicode 编码保存。在记事本中打开文件,通过将编码更改为“ANSI”来保存,并将文件另存为 fileName.php 并键入“所有文件”,编码为“ANSI”。
The file was being saved in UniCode Encoding. Opened the file in Notepad, and saved by changing the Encoding to "ANSI" and saved the file as fileName.php and type "All Files", Encoding as "ANSI".
确保扩展名是 .php
并检查 phpmanual 上的 echo 标签。
php.net/manual/en/function.echo.php
当您尝试在 echo 函数中包含 html 标签时,您需要在 "" 或 '' 之间插入并使用 .元素之间。
Make sure the extension is .php
and check echo tags on phpmanual.
php.net/manual/en/function.echo.php
When you try to include html tags inside echo function, you need to insert between "" or '' and use . between elements.
为了显示 PHP,或者运行嵌入的 PHP,您需要告诉 PHP 查看 HTM 和 PHP 的内部。 HTML 文件。
您需要在 HTML 目录的根文件夹中有一个名为
.htaccess
的文件,这是一个简单的文本文件,其中包含以下行:#AddType application/x-httpd-php 。 html .htm
这让 PHP 编译器知道在显示 HTML 页面时编译 php。
In order to display PHP, or run embededded PHP, you need to tell PHP to look inside the HTM & HTML files.
You need to have a file in the root folder of the HTML directory called
.htaccess
, which is a simple text file, with the following line:#AddType application/x-httpd-php .html .htm
This lets the PHP compiler know to compile the php when displaying the HTML page.
http://localhost/demo/demo.html 将不起作用。
http://localhost/demo/demo.php 可以工作。
php 在 .php 扩展名上工作。
祝你好运兄弟
http://localhost/demo/demo.html will not work.
http://localhost/demo/demo.php will work.
php work on .php extension.
Good Luck bro
检查您是否安装了 2 个以上版本的 PHP。服务器有时可能对此感到困惑。首先卸载 php 版本并仅重新安装一个 PHP 版本。
Check if you have installed more than 2 versions of PHP. The server may get confused sometime regarding this. First uninstall the php versions and reinstall only one PHP version.