Hey all,
Is there a way to merge two seperate sentences in a textfile, and by the user requesting what lines they want to merge, for example,
A textfile has
Line: 1 banana
2 orange
3 apple
4
5 pear
6 grape
7
8 Starfruit
The user types in textbox 1 - 3 and then types in textbox 2 - 6,, when saved it would produce:-
1 banana
2 orange
3 apple
4 grape
5
6 pear
7
8 Starfruit
Its for a larger textfile and so far i have created a bit of code but not sure how to complete it:-
<form method="post">
On line
<input type="text" name="line1">
<br>Before line
<input type="text" name="line2">
<br> Merge with
On line
<input type="text" name="line3">
<br>Before line
<input type="text" name="line4">
<br><input type="submit">
</form>
<p>Merge these two sections? <br><br>
<?php
$l1 = $_POST["line1"];
$l2 = $_POST["line2"];
if (isset($l1) && isset($l2)) {
$m = file_get_contents("testfile.txt");
$lines = explode("\n",$m);
if ($l2 < count($lines)) {
for ($i = $l1;$i < $l2;$i++) {
echo $lines[$i]."\n<br>";
}
}
else {
echo "Query must be less then: ".count($lines);
}
}
?>
<!--Second entry -->
<?php
$l3 = $_POST["line3"];
$l4 = $_POST["line4"];
if (isset($l3) && isset($l4)) {
$m = file_get_contents("testfile.txt");
$lines = explode("\n",$m);
if ($l4 < count($lines)) {
for ($i = $l3;$i < $l4;$i++) {
echo $lines[$i]."\n<br>";
}
}
else {
echo "Query must be less then: ".count($lines);
}
}
?>
<P>Read below to gather the correct line numbers to delete (soon text search)<br><br>
<?php
$strings = file('testfile.txt'); //Getting the file into an array by using file ()
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars(trim($line,"\r\n")) . "<br />\n";
}
?>
which i know has little potential so far lol.
ace