Given, In a input form user can separate some specific names by new line and i am saving those names in an array. Then I print those names and at last say something like "thank you for the names".
$var = "name1
name2
";
$your_array = explode("\n", $var);
for($i=0; $i<(sizeof($your_array));$i++) {
echo ($your_array[$i]);
}
echo "Thank you for the names"
But the problem is if someone enter more than one newline before or after a name then the next name show after some distance like below
name1
name2
Thank you for the names
How can escape this and output as below
name1
name2
Thank you for the names
I tried to use array_filter() but it don't work here.
Update:
If someone input
$var = "name1\nname2\n\n\n
name3
name4";
output should be like
name1
name2
name3
name4
But all the answers show like
name1
name2
name3
name4
$your_array = array_filter($your_array);