i need to Build a form textarea where someone enters a list of books (comma seperated). Use explode to populate an array of the book titles. Loop through and show the book titles on new lines.

any help will be gladly appriacated !

Recommended Answers

use explode function..
Assume $_POST is your form textarea name.
see this:

$names = explode(",", $_POST['textareaname']);
print_r($names );
foreach($names as $key=>$value)
{
echo $value;
}
Jump to Post

Try this:

echo "Book Names:<br>";
foreach($names as $key=>$value)
{
echo $value."<br>";
}

try this and tel me what printed on browser after submit button clicked..

Jump to Post

All 5 Replies

use explode function..
Assume $_POST is your form textarea name.
see this:

$names = explode(",", $_POST['textareaname']);
print_r($names );
foreach($names as $key=>$value)
{
echo $value;
}

thanks shanti :)

up to now my code is like this

<div class="wrapper">
<?php include("includes/header.php"); ?>
<?php include("includes/menu.php"); ?>
<div class="content">
<?php
if ($_POST)
	{
		$names = explode(",", $_POST['textareaname']);
		print_r($names );
		foreach($names as $key=>$value)
		{
		echo $value;
		}
	}
	else
	{
?>
<form method="post" action="">
Insert List of Books:<br />
<textarea name="textareaname" cols="60" rows="5"></textarea>
<input type="submit" value="submit"/>
</form>
<?php } ?>
</div>

what i need to do no is loop the array and show the entries on new lines, can you help me out one last bit ?

use explode function..
Assume $_POST is your form textarea name.
see this:

$names = explode(",", $_POST['textareaname']);
print_r($names );
foreach($names as $key=>$value)
{
echo $value;
}

Try this:

echo "Book Names:<br>";
foreach($names as $key=>$value)
{
echo $value."<br>";
}

try this and tel me what printed on browser after submit button clicked..

works like a charm :D thanks alot for your kind help!

mark it solved..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.