简体   繁体   中英

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. The problem i am having is when printing out the html it covers up my full page rather that only inside my table cell.

I have tried using an iframe and setting the SRC to the URL instead but the website has this blocked.

Is there a way to stop the html from taking over the full page and contain it into a cell?

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

Ex :

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

Suppose, demofileurl produces below output :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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