I am using below php code to process two textareas called namelist
and placelist
and echo it to html.
<?php
$namelist = $_POST['namelist'];
$placelist = $_POST['placelist'];
$names = explode("\n", $namelist);
$places = explode("\n", $placelist);
$entries = min(count($names), count($places));
for ($i = 0; $i < $entries; $i++) {
$name = trim($names[$i]);
$place = trim($places[$i]);
echo "My name is $name and I am from $place ".PHP_EOL;
}
?>
But above code processing the blank lines in my textareas ? I need to avoid blank lines from echoing.
for example, if the namelist
contains
Tom
George
and placelist
contains
GK
US
I will get output like:
My name is Tom and I am from GK
My name is George and I am from US
But If there is a blank line in an of the textarea it processing the blank line too. eg:
Tom
George
and
GK
US
It will give below output like
My name is Tom and I am from GK
My name is George and I am from