php include html文件,如何在HTML文件中从“include”调用后停止PHP回显“1”?(How to stop PHP echoing a “1” after being call...

如何在HTML文件中从“include”调用后停止PHP回显“1”?(How to stop PHP echoing a “1” after being called from “include” within a HTML file?)

我正在尝试通过在我的HTML代码中使用以下内容来调用我的导航栏:

= include 'subfolder/topbar.php'; ?>

但是,因为脚本成功运行,所以在我的页面继续呈现更多HTML之前,它在完成时回显“1”。 然后这会搞砸我页面中的间距。 我试图阅读(并查看类似的线程),但找不到工作分辨率。

如何在不完成时回显“1”的情况下包含PHP文件的内容?

我也尝试将include放在变量中,但它仍然输出“1”:

$myX = (include 'subfolder/topbar.php');

我也试过用:

include 'subfolder/topbar.php';

return ob_get_clean();

但这只是完全停止输出(因此页面的其余部分不会渲染),就像使用“exit”命令一样。

I'm trying to call my navigation bar by using the following within my HTML code:

= include 'subfolder/topbar.php'; ?>

However, because the script is successfully running, it's echoing a "1" on completion, before my page continues rendering more HTML. This is then screwing up the spacing within my page. I've tried to read up on this (and looked at similar threads) but can't find a working resolution.

How do I include the contents of the PHP file without it echoing "1" on completion?

I've also tried putting the include in a variable, but it still outputs the "1":

$myX = (include 'subfolder/topbar.php');

I've also tried using:

include 'subfolder/topbar.php';

return ob_get_clean();

But this just halts the output altogether (so the rest of the page doesn't render), much like using the "exit" command.

原文:https://stackoverflow.com/questions/35610146

更新时间:2019-09-18 10:50

最满意答案

应该是正确的方法

include 'subfolder/topbar.php'; ?>

要么

你的代码

= include 'subfolder/topbar.php'; ?>

就像说

echo include 'subfolder/topbar.php'; ?>

The correct way should be

include 'subfolder/topbar.php'; ?>

or

Your code

= include 'subfolder/topbar.php'; ?>

is like saying

echo include 'subfolder/topbar.php'; ?>

相关问答

应该是正确的方法 include 'subfolder/topbar.php'; ?>

要么 <?php include 'subfolder/topbar.php'; ?>

你的代码 = include 'subfolder/topbar.php'; ?>

就像说 echo include 'subfolder/topbar.php'; ?>

The correct way should be include 'subfolder/topbar.php'; ?>

...

即使用MAMP进行测试,这对我也没有用。 有一个更好的方法吗? 您可以通过回显header.php和footer.php的HTML代码来包含它。 直接将.html文件重命名为.php将不起作用。 我听说包含include的文件的文件扩展名需要是php。 您的文件必须是PHP,否则您不能include它。 但是,您可以指示系统使用.htaccess将.html文件视为.php文件。 (感谢@Fred -ii-指出) 资料来源: http : //php.net/manual/en/function.

...

function rowFromVar($last_modified) {

$result = <<

function ago(\$time)

{

\$periods = array("second", "minute",

...

您似乎将内容回显到已经具有基本HTML框架的网站(打开html标记等)。 如果查看输出,可以看到有2个html ,2个body和2个head标记,每个网站只能出现一次 。 我想你的脚本会将你的脚本输出回显到

标签中。 尝试这个回声,看看它是否会导致你想要的输出: echo "

这应该可以达到你要找的东西: echo '

'.$get_row['name'].'
'.$get_row['description'].''.%24get_row%5B'imagesrc'%5D.'
£'.number_format($get_row['price'],2).'Add

';

'字符定义了一个字符串文字,当它包裹在一系列字符中

...

而不是直接调用函数,您可以使用$ row 改变

...

如果您是新手,请不要手动设置PHP,Apache和MySQL; 而是下载并安装WAMPServer以快速启动并运行。 这将在您的c:/驱动器中创建一个充当根主机的目录 - 当WAMP(Windows,Apache,MySQL和PHP)运行时,您将能够通过访问http://localhost/来访问它。 其次,请务必将PHP代码放在.php文件中,而不是.html文件中。 Apache可能没有配置为在.html文件中解释PHP,但它会对.php文件执行此操作。 如果您想要安装WAMPServer的视

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值