Entry
How do I, in PHP, list lines of text in a multi-line listbox (not a drop down listbox)?
Nov 13th, 2000 17:09
Ben Udall, D. Singh, http://www.php.net/manual/function.explode.php
I'm assuming the text you want to list, is a single string. In this
case, you can use the explode() function to convert the string into an
array of lines. Below is a small example to get you started:
// The text is in the string $text
// If windows style lines breaks are used, convert to unix style
$new_text = ereg_replace("\r\n", "\n", $text);
// Convert the text string to an array of lines
$lines = explode("\n", $new_text);
// Print out the list box
print "<SELECT name='lines' size='10'>\n";
foreach ($lines as $line_text)
print " <OPTION>" . htmlentities($line_text) . "</OPTION>\n";
print "</SELECT>\n";