Search code examples
phphtml-tablefwrite

PHP table creation in fwrite HTML


I have created an HTML form that passes information to a PHP file.

I have used fwrite to create an HTML file that includes variables from the form.

In order to create a table I have this:

for($i = 0; $i < count($docresult); $i++){
echo "<tr><td>$i. </td><td><a href=\\docs\\\"$docresult[$i]\">$docresult[$i]</a></td><td>$txtresult[$i]</td><tr>";
}

What is best practice for placing this within a string? Basically, I want this to work:

$DataToFwrite = "
    <table border=\"1\">
for($i = 0; $i < count($docresult); $i++){
echo "<tr><td>$i. </td><td><a href=\\docs\\\"$docresult[$i]\">$docresult[$i]</a></td><td>$txtresult[$i]</td><tr>";
}
    </table>";
fwrite($FileHolder, $DataToFwrite);

I have no idea how to do this! I am new to PHP and would appreciate any help.


Solution

  • I am not sure, try this one

    $DataToFwrite = "<table border='1'>";
    for($i = 0; $i < count($docresult); $i++){
        $href = "docs\\".$docresult[$i];
        $DataToFwrite .= "<tr><td>$i</td><td><a href='$href'>".$docresult[$i]."</a></td><td>".$txtresult[$i]."</td><tr>";
    }
    $DataToFwrite .= "</table>";
    fwrite($FileHolder, $DataToFwrite);