I'm beginner in php and i tried to realize a soft for my personnal use.
In a teaxarea field name "players", i want to grab each line and use the data in it at my will.
For eg :
My html code is :
<form method="post">
<p>
<label for="players">PLAYER :</label>
<br>
<textarea id="players" name="players" rows="4" cols="50"></textarea>
</p>
<p><input type="submit" value="CREATION"></p>
If in this teaxtarea i wrote this :
NAME FIRSTNAME ID BIRTHDATE
OTHERNAME OTHERFIRSTNAME OTHERID OTHERBIRTHDATA
I want to be able to use Name, Firstname, Id, Birthdate and go for the other line and this for each line.
At the beginning I tried this Get each line from textarea but it look like is not working for me : my idea was to use this with a $data=explode(" ", $line); to get an array on what I want.
Currently my result :
<?php
if (!empty($_POST['players']){
echo "WORKING";
$text = trim($_POST['players']);
$textAr = explode("\n", $text);
$textAr = array_filter($textAr, 'trim'); // remove any extra \r characters left behind
foreach ($textAr as $line) {
$player=explode("/" , $line);
echo $player[0]; // processing here.
echo $player[1]; // processing here.
echo $player[2]; // processing here.
echo $player[3]; // processing here.
echo $player[4]; // processing here.
}
}
?>