I have an index page that takes a user input list of items separated by a space. It processes that list as an array and replaces the white space with a ", ". However, my PHP script doesn't seem to do that and I'm not sure I understand why.
index.php
<form action="process.php" method="post">
<b>Enter a list of items separated by a space:</b> <br><input name="list[]" type="text">
<input type="submit">
</form>
process.php
<?php
$list = $_POST["list"];
$list = preg_replace('#\s+#',', ',trim($list));
echo "<b>Your listed items were:</b> $list";
?>
Any help in understanding this would be greatly appreciated! Thanks!
EDIT Thanks a lot everyone! Seems like my issue was a fairly novice one and fixing it was pretty easy.
$listis an array of inputs. Process it as an array$list = explode(' ', $list);That will make it an array. Then, you can loop through the array posting the values.