1

I have a data from the database that store user's input from a Textarea box.

This is an example of user's input in the Textarea box;

iPhone
Samsung
Nokia

When I saved it into the database, I want to display that data to become like this in a table;

1. iPhone
2. Samsung
3. Nokia

So how am I going to display the data with the numbering?

This is my code so far;

<table>

     <td align="left"><?php echo nl2br($sis_sistem) ?></td>

</table>

Note : $sis_sistem is the variable that store the data from the database.

4

1 に答える 1

3

explode() into an array on the line breaks, then iterate over it. Rather than numbering them with plain text, you ought to make them a proper HTML ordered list <ol>

// Get an array of items from lines
$list = explode("\n", $sis_sistem);

// Open an ordered list
echo "<ol>";
// Output the items as list elements
foreach ($list as $num => $item) {
  echo "<li>" . htmlspecialchars($item) . "</li>";
}
echo "</ol>";
于 2012-04-26T03:09:00.277 に答える