What I want to achieve:
1. User pastes around ~50 rows of data into a textarea which looks something like this:
aosijpoaspo4koas4
aso4kaps4kaso4pas
4asp4sak,as4aposk4paos
paosk4poas,asas4as4aspkoå4as
as4kopasap sk4poask45 4k4 4
4 rkop43kr p4
¤p 43kpo4 kp¤PO k4
4pw ok4
,4ok po4w ,
4opkrpo4rp4o
2. I want to remove all lines that does NOT contain a comma, this should be fairly easy by first exploding the string with \n as separator and make it become and array (which I have done in my code)
3. Then I want to print out all the lines which has a comma.
I am stuck here and my head spins a lot because of all this thinking. Does it mean I am stupid? This is very hard for me.
First problem is that I can't check the length of an array with strlen so that's where I am currently stuck...
if(isset($_POST['usernames'])) {
$str = $_POST['usernames'];
//Explode $str to an array, each line separated by line breaks \n
$arr = explode("\n", $str);
//If row contains "," add it to an array and print it
for ($x = 0; $x < strlen($arr); $x++) {
if (preg_match('/,/',$arr[$x])) {
echo $arr[$x] . "<br>";
}
}
}
Yep I got a spelling error in the title but I can't change it...