faqts : Computers : Programming : Languages : PHP : Common Problems : Arrays

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 21 people (57%) answered Yes
Recently 5 of 10 people (50%) answered Yes

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";