PHP loop does not write text sequentially
Here is my code snippet:
foreach ($row as $key => $val) {
echo "<div class='jmp'><b>". htmlentities($key).": </b><br>"
.htmlentities($val)."</div>\n";
}
Oddly enough, PHP sometimes displays like this:
<div class='jmp'><b>HDD_SIZE_GB:</b><br> 143.5</div>
<div class='jmp'><b>HDD_MODEL:b><br> SEAGATE STT14775 </div>
<div class='jmp'><b>HDD_SN:</b><br> 3LN3N0098271QL2</div>
Notice that the ending <is missing a "b" in the middle? What is causing this? There are 500 records in the database. Even more perplexing, it is consistent. When I refresh the page, this error on that particular line will go away, but an identical error will appear on other lines. This completely breaks strict XHTML parsing.
+3
netrox
source
to share
2 answers
My comment as an answer:
Are you sure this is the original output (try it on the command line or with lynx)? Sometimes browsers will change the code ...
+1
Green black
source
to share
How your array is created. So it should work as expected
$row = array();
$row['HDD_SIZE_GB'] = '143.5';
$row['HDD_MODEL'] = 'SEAGATE STT14775';
$row['HDD_SN'] = '3LN3N0098271QL2';
-3
Wezy
source
to share