View Full Version : how to modify the .txt file?
phpfish
09-03-2008, 09:13 PM
hi! i found a .txt file modifier script, which is located here: http://www.dynamicdrive.com/forums/archive/index.php/t-4539.html but if i tried to write HTML code inside to textarea and submitted it then the script didnt show the html tags...
what's the problem? im noob <- it means that I cant fix it by myself...
is it possible to change this script somehow to show html code? :confused:
Change:
if($_POST['addition']) fwrite($file, $_POST['addition']);
To this:
if($_POST['addition']){ fwrite($file, $_POST['addition']); header("Location: ".$_SERVER["PHP_SELF"]); }
phpfish
09-04-2008, 07:56 AM
Change:
if($_POST['addition']) fwrite($file, $_POST['addition']);
To this:
if($_POST['addition']){ fwrite($file, $_POST['addition']); header("Location: ".$_SERVER["PHP_SELF"]); }
thanks :) it worked
phpfish
09-04-2008, 07:57 AM
but could you do the same with this php script(it means how to add this code:
if($_POST['addition']){ fwrite($file, $_POST['addition']); header("Location: ".$_SERVER["PHP_SELF"]); }
inside to this script:
<?
if($_POST['Submit']){
$open = fopen("textfile.txt","w+");
$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 />";
}
echo "<p><a href=\"./livepage.php\">click here to view the live updated webpage</a></p>";
echo "<p><a href=\"./mainadminpage.php\">click here to view the admin menu</a></p>";
}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>";
}
?>
this script also helps to erase the data from the .txt file <- its why I chosen it
motormichael12
09-04-2008, 01:15 PM
If you mean you want it to show the form even after updating, try this:
<?
if($_POST['Submit']){
$open = fopen("textfile.txt","w+");
$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 />";
}
echo "<p><a href=\"./livepage.php\">click here to view the live updated webpage</a></p>";
echo "<p><a href=\"./mainadminpage.php\">click here to view the admin menu</a></p>";
}
$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>";
?>
phpfish
09-04-2008, 01:43 PM
If you mean you want it to show the form even after updating, try this:
<?
if($_POST['Submit']){
$open = fopen("textfile.txt","w+");
$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 />";
}
echo "<p><a href=\"./livepage.php\">click here to view the live updated webpage</a></p>";
echo "<p><a href=\"./mainadminpage.php\">click here to view the admin menu</a></p>";
}
$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>";
?>
it works well, but if i try to write some code:
<?xml version="1.0" encoding="UTF-8" ?>
<playlist version="0" xmlns="http://xspf.org/ns/0/">
<title>mp3player</title>
<creator>kaboom!</creator>
<trackList>
<track>
<location>http://www.kaboom.com/example_song.mp3</location>
<identifier>684088:Track:1639</identifier>
<title>This is a example</title>
<creator>This is a example</creator>
<image>http://www.kaboom.com/example_artist.jpg</image>
<extension application="http://docs.ning.com/music/">
</extension>
</track>
</trackList>
</playlist>
then the script itself adds excessively "slashes" which is actually unnecessary.. it makes the code unreadable and the mp3player is unable to read the code...
how can i solve the problem? is it possible?
phpfish
09-04-2008, 01:45 PM
heres the result:
<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<playlist version=\"0\" xmlns=\"http://xspf.org/ns/0/\">
<title>mp3player</title>
<creator>kaboom!</creator>
<trackList>
<track>
<location>http://www.kaboom.com/example_song.mp3</location>
<identifier>684088:Track:1639</identifier>
<title>This is a example</title>
<creator>This is a example</creator>
<image>http://www.kaboom.com/example_artist.jpg</image>
<extension application=\"http://docs.ning.com/music/\">
</extension>
</track>
</trackList>
</playlist>
motormichael12
09-04-2008, 03:08 PM
try this:
replace:
if($_POST['Submit']){
$open = fopen("textfile.txt","w+");
$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 />";
}
with
if($_POST['Submit']){
$open = fopen("textfile.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />";
echo "File:<br />";
$file = file("textfile.txt");
foreach($file as $text) {
echo stripslashes($text)."<br />";
}
phpfish
09-04-2008, 06:43 PM
try this:
replace:
if($_POST['Submit']){
$open = fopen("textfile.txt","w+");
$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 />";
}
with
if($_POST['Submit']){
$open = fopen("textfile.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />";
echo "File:<br />";
$file = file("textfile.txt");
foreach($file as $text) {
echo stripslashes($text)."<br />";
}
sry, but it didnt work (unnecessary slashes are still in code, when i try to modify the data)..
phpfish
09-04-2008, 07:46 PM
everything works fine, but when there's a an equal signinside inside the code then the code itself adds some unnecessary slashes after the signinside..
phpfish
09-04-2008, 07:48 PM
is it possible to erase signinsides from the code somehow(code has to work then too):
<?xml version="1.0" encoding="UTF-8" ?>
<playlist version="0" xmlns="http://xspf.org/ns/0/">
<title>mp3player</title>
<creator>kaboom!</creator>
<trackList>
<track>
<location>http://www.kaboom.com/example_song.mp3</location>
<identifier>684088:Track:1639</identifier>
<title>This is a example</title>
<creator>This is a example</creator>
<image>http://www.kaboom.com/example_artist.jpg</image>
<extension application="http://docs.ning.com/music/">
</extension>
</track>
</trackList>
</playlist>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.