Reputation: 363
I have a HTML form and there is a textarea let's say like this:
link1
link2
link3
I would like to take the text from the text area row after row through PHP file so it will in the end be like this:
$var1 will be "link1"
$var2 will be "link2"
$var3 will be "link3"
important - this variables must be saved in php - whole form is in html file
EDIT: this can be done with array too, so i will have ["link1", "link2", "link3"]
EDIT2: if this is done with array i would like to acces it with indexes like in JS or other languages so "$array[0]" for example... (i know its not done like this in php)
Upvotes: 0
Views: 199
Reputation: 63
In this case you can use a foreach
.
Let's say you have a textarea
tag.
<textarea name="lyrics"></textarea>
You can access it's value:
$lyrics = $_POST['lyrics'];
$text = trim($lyrics);
$textAr = explode("\n", $text);
$textAr = array_filter($textAr, 'trim');
Use foreach
foreach ($textAr as $line)
{
echo $line;
}
Upvotes: 1