Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: how to modify the .txt file?

  1. #1
    Join Date
    Sep 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to modify the .txt file?

    hi! i found a .txt file modifier script, which is located here: http://www.dynamicdrive.com/forums/a...hp/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?
    Last edited by phpfish; 09-03-2008 at 09:19 PM. Reason: i wrote something wrong

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Change:
    PHP Code:
    if($_POST['addition']) fwrite($file$_POST['addition']); 
    To this:
    PHP Code:
    if($_POST['addition']){ fwrite($file$_POST['addition']); header("Location: ".$_SERVER["PHP_SELF"]); } 
    Jeremy | jfein.net

  3. #3
    Join Date
    Sep 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    Change:
    PHP Code:
    if($_POST['addition']) fwrite($file$_POST['addition']); 
    To this:
    PHP Code:
    if($_POST['addition']){ fwrite($file$_POST['addition']); header("Location: ".$_SERVER["PHP_SELF"]); } 
    thanks it worked

  4. #4
    Join Date
    Sep 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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
    Last edited by phpfish; 09-04-2008 at 08:05 AM.

  5. #5
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    If you mean you want it to show the form even after updating, try this:

    Code:
    <?
    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>";
    ?>

  6. #6
    Join Date
    Sep 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by motormichael12 View Post
    If you mean you want it to show the form even after updating, try this:

    Code:
    <?
    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:
    PHP 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?

  7. #7
    Join Date
    Sep 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    heres the result:
    PHP 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>

  8. #8
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    try this:

    replace:

    Code:
    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

    Code:
    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 />";
    }

  9. #9
    Join Date
    Sep 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by motormichael12 View Post
    try this:

    replace:

    Code:
    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

    Code:
    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)..

  10. #10
    Join Date
    Sep 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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..

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •