Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Is it possible to write to a text file in html  (Read 5332 times)

0 Members and 1 Guest are viewing this topic.

zask

    Topic Starter


    Intermediate

    • Experience: Experienced
    • OS: Other
    Is it possible to write to a text file in html
    « on: March 30, 2016, 06:32:08 PM »
    Hello, I was wondering if it is possible to create a text file with text in it from html, and if so, is it possible to specify a name for that text file as well?

    I've tried using this code but it doesn't work and i dont know the proper way to create a htaccess file because i've never used php before, so i need help with doing that.

        <html>

       <head>
       <title>Writing to a text file</title>
       </head>
       <body>

       <?php

       // Open the text file
       $f = fopen("textfile.txt", "w");

       // Write text line
       fwrite($f, "PHP is fun!");

       // Close the text file
       fclose($f);

       // Open file for reading, and read the line
       $f = fopen("textfile.txt", "r");
       echo fgets($f);

       fclose($f);

       ?>

       </body>
       </html>

    Lastly can someone explain what this code is doing specifically? Thank  you.

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Is it possible to write to a text file in html
    « Reply #1 on: March 30, 2016, 06:54:26 PM »
    You can't have php code in a html file. PHP is run on the server side, so it must be run on a server.
    I was trying to dereference Null Pointers before it was cool.

    zask

      Topic Starter


      Intermediate

      • Experience: Experienced
      • OS: Other
      Re: Is it possible to write to a text file in html
      « Reply #2 on: March 30, 2016, 07:13:45 PM »
      but iv'e seen this done before, maybe im not saying correctly what i want.

      im looking for something like in this video, it explains what i mean.

      https://www.youtube.com/watch?v=ka5m_kvQUFo

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Is it possible to write to a text file in html
      « Reply #3 on: March 30, 2016, 07:21:41 PM »
      Oh. I see. You have a web server. you don't want to write to a text file in HTML; you want to write to a text file in PHP, and you want the apache server to run .html files through mod_php.

      If you can't change .htaccess you can change your server's configuration. For apache it is /etc/apache2/mods-enabled/php5.conf on *nix though I'm not sure where it would be on windows.
      You can add this to the file:

      Code: [Select]
      <FilesMatch ".+\.html$">
          SetHandler application/x-httpd-php
      </FilesMatch>
      I was trying to dereference Null Pointers before it was cool.

      zask

        Topic Starter


        Intermediate

        • Experience: Experienced
        • OS: Other
        Re: Is it possible to write to a text file in html
        « Reply #4 on: March 30, 2016, 07:34:27 PM »
        Exactly, Do you know specifically how i can do this? like for example, where specifically do i do what on the web server?
        Or do you know anywhere where i can have a good start in trying to learn to
        do this?

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Is it possible to write to a text file in html
        « Reply #5 on: March 30, 2016, 07:46:24 PM »
        Exactly, Do you know specifically how i can do this? like for example, where specifically do i do what on the web server?
        Or do you know anywhere where i can have a good start in trying to learn to
        do this?

        If you have access to the web server you should be able to create a .htaccess file (leading period) in much the same way you would create other files. At which point I'd expect that the video you linked describes what you need to add to have it process .html as .php files.
        I was trying to dereference Null Pointers before it was cool.

        zask

          Topic Starter


          Intermediate

          • Experience: Experienced
          • OS: Other
          Re: Is it possible to write to a text file in html
          « Reply #6 on: April 02, 2016, 11:59:45 AM »
          If you have access to the web server you should be able to create a .htaccess file (leading period) in much the same way you would create other files. At which point I'd expect that the video you linked describes what you need to add to have it process .html as .php files.

          Yes thats correct