skip to Main Content

I am trying to retrieve the code from an HTML file in PHP.

And display it in a textarea.

Example: if I have a file with a div and a foo h1 in it I want my textarea to appear like this.

After a few hours of research, I can’t find a good result.

Here is my sample html file

And I want this html file to be readable in a textara that I styled.

Example right here of stylized file

Thank you in advance for your lights !

Exemple result display

I tried to use fopen in order to be able to open the file and read it but I cannot convert my string into an html tag.

2

Answers


  1. You should use readfile():

    readfile("/path/to/file");
    

    This will read the file and send it to the browser in one command. This is essentially the same as:

    echo file_get_contents("/path/to/file");
    

    except that file_get_contents() may cause the script to crash for large files, while readfile() won’t.

    Login or Signup to reply.
  2. Your can try using jQuery, below is the example code:

    <html> 
      <head> 
        <script> 
        $(function(){
          $("#includedContent").load("b.html"); 
        });
        </script> 
      </head> 
    
      <body> 
         <div id="includedContent"></div>
      </body> 
    </html>
    

    OR

    Reference link: https://www.w3schools.com/howto/howto_html_include.asp

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search