我正在使用下面的 php 代码来处理两个调用的文本区域namelist
并将placelist
其回显到 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;
}
?>
但是上面的代码处理我的 textareas 中的空白行?我需要避免空行回显。例如,如果namelist
包含
Tom
George
并placelist
包含
GK
US
我会得到如下输出:
My name is Tom and I am from GK
My name is George and I am from US
但是如果文本区域中有一个空行,它也会处理空行。例如:
Tom
George
和
GK
US
它将给出以下输出,例如
My name is Tom and I am from GK
My name is George and I am from