Feb 1, 2019 01:35 PM
(This post was last modified: Feb 1, 2019 01:50 PM by Topkek_Is_Life.)
I am trying to convert my html table to a php array. (Table here: http://goldenjoe.xyz/messages/), but I seem to be having a problem. The rows are generated using a json file and the php script reads directly from the index.html on the server, which shows the tbody is empty (because they are generated).
php:
index.html:
When I run the php I get the error
Which makes sense because the variable "aDataTableDetailHTML" is declared in the foreach loop, but that loop isn't running because it does not see any <td> tags in the index.html
When you load the actual site up though, the table loads and the <td> tags are present.
Spoiler (Click to View)
Does anyone here know of a workaround I could use. I've been trying to download the complete webpage and generate a separate html file to use, but wget and curl just download the index.html directly off the server.
php:
PHP Code
<?php
$htmlContent = file_get_contents("http://goldenjoe.xyz/messages/");
$DOM = new DOMDocument();
$DOM->loadHTML($htmlContent);
$Header = $DOM->getElementsByTagName('th');
$Detail = $DOM->getElementsByTagName('tr');
//#Get header name of the table
foreach($Header as $NodeHeader)
{
$aDataTableHeaderHTML[] = trim($NodeHeader->textContent);
}
//print_r($aDataTableHeaderHTML); die();
//#Get row data/detail table without header name as key
$i = 0;
$j = 0;
foreach($Detail as $sNodeDetail)
{
$aDataTableDetailHTML[$j][] = trim($sNodeDetail->textContent);
$i = $i + 1;
$j = $i % count($aDataTableHeaderHTML) == 0 ? $j + 1 : $j;
}
print_r($aDataTableDetailHTML); die();
?>index.html:
Code
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
var messages = [];
$.getJSON('messages.json', function(data) {
$.each(data.items, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.storage.url +
"<td>" + f.message.headers.to + "<td>" + f.message.headers.subject + "<td>"
$(tblRow).appendTo("#userdata tbody");
});
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id= "userdata" border="2">
<thead>
<th>Url</th>
<th>Target</th>
<th>Subject</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>When I run the php I get the error
Code
Notice: Undefined variable: aDataTableDetailHTML in /home/gueruex/public_html/messages/test2.php on line 26Which makes sense because the variable "aDataTableDetailHTML" is declared in the foreach loop, but that loop isn't running because it does not see any <td> tags in the index.html
When you load the actual site up though, the table loads and the <td> tags are present.
Spoiler (Click to View)
Does anyone here know of a workaround I could use. I've been trying to download the complete webpage and generate a separate html file to use, but wget and curl just download the index.html directly off the server.


