0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
kadeshiseraph
  • 65
  • 1
  • 8

1 Answers1

2

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);
Miqdad Ali
  • 6,129
  • 7
  • 31
  • 50