简体   繁体   English

将file_get_contents打印到div中

[英]Print file_get_contents into a div

I have a few URLS that i am looping through and using file_get_contents to pull the html page, what i am trying to do is create a table on my website and have each row show the returned HTML for each page. 我有几个URL,这些URL循环遍历并使用file_get_contents拉动html页面,我试图做的是在我的网站上创建一个表,并让每一行显示每个页面返回的HTML The problem i am having is when printing out the html it covers up my full page rather that only inside my table cell. 我遇到的问题是在打印html时它覆盖了我的整个页面,而不是只覆盖了我的表格单元格。

I have tried using an iframe and setting the SRC to the URL instead but the website has this blocked. 我尝试使用iframe并将SRC设置为URL,但是该网站已被阻止。

Is there a way to stop the html from taking over the full page and contain it into a cell? 有没有一种方法可以阻止html接管整个页面并将其包含在单元格中?

Use strip_tags(file_get_contents(URL_OF_FILE)) . 使用strip_tags(file_get_contents(URL_OF_FILE)) Raw HTML from those third party sites are messing with HTML structure of your page and broke the table layout. 这些第三方网站的原始HTML弄乱了页面的HTML结构,破坏了表格布局。

Ex : 例如:

<table>
<tr>
<td><?php echo file_get_contents('demofileurl');?></td>
</tr>
</table>

Suppose, demofileurl produces below output : 假设demofileurl产生以下输出:

<div style="height:5000px;border:1px solid red">
 Hello World 
<table>
 <tr>
 <td>teststetest

</div>

So you can get an idea from above example, any invalid HTML in those third party sites can broke your HTML structure. 因此,您可以从上述示例中了解到这些第三方网站中的任何无效HTML都可能破坏您的HTML结构。

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

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