list to php array list2phparray

Code below for a script to take a list and turn it into an array. Comes in pretty useful.


if ($_POST[‘list’]) {
$splist = explode(“\n”, $_POST[‘list’]);
$out = ‘$x = array(‘;
foreach ($splist as $line) {
$out = $out.”‘$line’, “;
$out = substr($out,0,-1);
$out = substr($out,0,-1);
$out = $out.’);’;

echo $out;

} else {
echo ‘<html><body>’;
echo ‘<h1>List 2 php array</h1>’;
echo ‘<form action=”list2phparray.php” method=”post”>
<textarea cols=”100″ rows=”30″ name=”list”></textarea>
<input name=”Submit” type=”submit” value=”Submit” />


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *