0

I have a table stored in an HTML file and I want to insert that into a WordPress page. I used echo file_get_contents('table.html') but it didn't display anything. Then I tried echo htmlentities (file_get_contents('table.html')). This just outputs the HTML code into the page but does not render it. How do I make the table display correctly ?

HTML table is something like:

<table class="fao-pricing-table-additional">
 <tr>
    <th class="fao-table-plan-details-header" rowspan="2">Plan Details</th>
    <th class="fao-table-plan-starter-header">STARTER</th>
    <th class="fao-table-plan-business-header">BUSINESS</th>
    <th class="fao-table-plan-enterprise-header">ENTERPRISE</th>
    <th class="fao-table-plan-corporate-header">CORPORATE</th>
</tr>
<tr>.......
  • If i understand your question correctly [this](https://wordpress.org/plugins/insert-html-snippet/) will help. This plugin will add HTML, CSS and javascript code to your pages and posts easily using shortcodes. – wolfsgang Jan 17 '16 at 07:55
  • Thank you replying. I just tried that but It didn't output anything. – Indika Ratnayake Jan 17 '16 at 08:04
  • check this out http://stackoverflow.com/questions/9539849/how-to-echo-the-whole-content-of-an-html-file-in-php – katwekibs Jan 17 '16 at 08:06
  • @IndikaRatnayake check out my updated answer and see if that works – Cup of Java Jan 17 '16 at 08:07
  • @katwekibs I tried readfile() but it output a number and does not render the HTML table. – Indika Ratnayake Jan 17 '16 at 08:25
  • Is it not outputting anything or can you just not see it in oyour html page? Check in the html source whether the html has been output or not? It is very unlikely that it works when calling html_entities but not otherwise! – Toby Allen Jan 17 '16 at 08:27
  • @wolfsgang Thank you very much. That's exactly what I was looking for. However I want to learn how to do it manually. – Indika Ratnayake Jan 17 '16 at 08:35

2 Answers2

1

You can just use an include() statement to render HTML/PHP on a webpage

Example

<div>
  <p>The table will be between this paragraph</p>

    <?php 
        include("table.html");
    ?>

  <p>And this paragraph</p>
</div>
Cup of Java
  • 1,769
  • 2
  • 21
  • 34
0

Use './' to indicate the relative path to the file.

Example: echo file_get_contents("./table.html");

Nuno Alex
  • 116
  • 3