when im inserting some text into following text field and press "submit" button to save it, then it saves the written data by back-to-back order..
here's the script:
<?
if($_POST['Submit']){
$open = fopen("textfile.txt","a+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />";
echo "File:<br />";
$file = file("textfile.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("textfile.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>
i read some topics too but i was unable to find something useful..
How to put text file into alphabetical order?
Moderator: General Moderators
Re: How to put text file into alphabetical order?
Code: Select all
<?
if($_POST['Submit']){
$open = fopen("textfile.txt","a+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />";
echo "File:<br />";
$file = file("textfile.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("textfile.txt");
sort($file);
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>Which sort of does the trick otherwise i think it'll be a pain in the button....are you modifying the textarea?
Re: How to put text file into alphabetical order?
i dont knowbaileylo wrote:So i'm sorting the textfile before you output it to the textarea.Code: Select all
<? if($_POST['Submit']){ $open = fopen("textfile.txt","a+"); $text = $_POST['update']; fwrite($open, $text); fclose($open); echo "File updated.<br />"; echo "File:<br />"; $file = file("textfile.txt"); foreach($file as $text) { echo $text."<br />"; } }else{ $file = file("textfile.txt"); sort($file); echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">"; foreach($file as $text) { echo $text; } echo "</textarea>"; echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n </form>"; } ?>
Which sort of does the trick otherwise i think it'll be a pain in the button....are you modifying the textarea?
Re: How to put text file into alphabetical order?
and the text file is here: http://hot.ee/antsman333/list.txt