I'm new in php. What I'm trying to do is to upload a file, generate it's content in textarea, select a delimiter and then split the lines according to what delimiter is selected in a html table. The html table is in another form. I have no problem with generating the content and with the delimiters. The code works with statically set string. The problem comes when I try to pass the content of the textarea into the html table.
I'd be grateful if someone could help.
Here's the 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>
And here's the 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("
", $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>';
}
?>
I'm taking the delimiter from here:
<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>
echo "<div contenteditable><tr></div>";
This is not allowed in html, due to incorrect nesting of tags.
You might want to try something like this:
foreach($lines as $line) {
echo "<div contenteditable><tr>";
$elements = explode($_POST['delimiter'], $line);
foreach($elements as $element) {
echo "<td>" . $element . "</td>";
}
echo "</tr></div>";
}
Anyhow, could you explain any further what kind of problem occurs to you?
Greetz