简体   繁体   English

如何在html div中显示php文件输出?

[英]How to display php file output inside a html div?

Alright, so I'm trying to embed a php script that outputs a gallery of images onto my html div container. 好吧,所以我试图嵌入一个php脚本,该脚本将图像库输出到我的html div容器中。 However, after an hour or so of searching I'm coming up clueless. 但是,经过一个小时左右的搜索,我变得毫无头绪。

http://craftedbyfrank.com/test/instagram.php http://craftedbyfrank.com/test/instagram.php

That's the link to the php gallery script. 那是到php gallery脚本的链接。

I want to display it onto the main page inside that div. 我想将其显示在该div的主页上。 [REMOVED] - thanks! [已删除]-谢谢!

I've tried the following, but I believe it's just wrong. 我已经尝试了以下方法,但是我相信这是错误的。 I get no output. 我没有输出。

 <div id="container">
 <?php include "instagram.php"; ?>
 </div>

I'm trying to avoid actually pasting the php script into the html file. 我试图避免实际上将php脚本粘贴到html文件中。

php is not being parsed on your server. 尚未在您的服务器上解析php。 If you view the html source you see the actual php code you are using to include the file. 如果您查看html源代码,则会看到用于包含文件的实际php代码。 Make sure that php is installed or you're not embedding the php from a cms that's encoding your tags. 确保已安装php,或者您没有从对代码进行编码的cms中嵌入php。

You could possibly use AJAX to get the result from the PHP file and write to the containing div. 您可能使用AJAX从PHP文件中获取结果并写入包含的div。

$.ajax({
    type:'GET',
    url:'http://craftedbyfrank.com/test/instagram.php',
    data:'',
    success: function(data){
            $('#container').html(data);
    }
});

You would possible need to adjust to get your fancy box plugin to work. 您可能需要进行调整才能使您的精美盒子插件正常工作。

As @vletech suggested you can use AJAX to get the result from the php file. 正如@vletech建议的那样,您可以使用AJAX从php文件中获取结果。

However the main reason why it does not work is because you are trying to execute the php script inside an .html file: eg your page loads on - /test/index.html . 但是,它不起作用的主要原因是因为您试图在.html文件中执行php脚本:例如,您的页面加载在-/ test/index.html上 In order to work the file has to be with a .php extension. 为了工作,该文件必须带有.php扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM