我是 php 新手。我想要做的是上传一个文件,在 textarea 中生成它的内容,选择一个分隔符,然后根据在 html 表中选择的分隔符拆分行。html 表是另一种形式。我对生成内容和分隔符没有任何问题。该代码适用于静态设置的字符串。当我尝试将 textarea 的内容传递到 html 表中时,问题就来了。
如果有人可以提供帮助,我将不胜感激。
这是HTML:
<form action="<?php session_start(); $areaText = $_POST['output']; $selected_radio = $_POST['delimiter']; echo $_SERVER['PHP_SELF'] ?>"
<?php
if (!empty($_FILES['uploadedfile']) && file_exists($_FILES['uploadedfile']['tmp_name'])&& $_FILES['uploadedfile']['type'] == 'text/plain') {
$file1 = $_FILES['uploadedfile']['tmp_name'];
$lines = file($file1);
foreach($lines as $line_num => $line)
{
echo $line;
}
}
else {
echo "Sorry, you're not allowed to upload these type of files.";
}
?></textarea>
</form>
这是PHP:
if (isset($_POST['output'])) {
$string = $_POST['output'];
$trimmedString = trim($string);
echo '<div contenteditable><table id = "TestTable" border="1" width="100%" id="table1">';
$lines = explode("\n", $trimmedString);
foreach($lines as $line) {
echo "<div contenteditable><tr></div>";
$elements = explode($_POST['delimiter'], $line);
foreach($elements as $element) {
echo "<td>" . $element . "</td>";
}
echo "</tr>";
}
echo '</table></div>';
}
?>
我从这里取定界符:
<form method="post" id="form_732147" class="appnitro" method="post" action="page2.php">
<span>
<label class="description" for="element_4">Choose a delimiter: </label>
<input type="radio" name="delimiterr" value="," >Comma</br>
<input type="radio" name="delimiter" value="." >Fullstop</br>