My goal is to import / open anything from an HTML file to a <textarea>
that is visible to the user on the web page and formated as HTML.
I have the following code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><!-- Insert your title here --></title>
</head>
<body>
<!-- start import -->
<textarea>
<html>
<head>
<title><!-- Insert your title here --></title>
</head>
<body>
imported HTML code, imported HTML code, imported HTML code, imported HTML code, imported HTML code, imported HTML code, imported HTML code, imported HTML code, imported HTML code,
</body>
</html>
</textarea>
<!-- End import -->
</body>
</html>
How do I import / upload a HTML file to a <textarea>
?
How do I format code in <textarea>
with colors, indent like as Notepad + +, Komodo etc formatting code.
I think
http://ace.ajax.org/#nav=about
and
http://www.cdolivet.com/editarea/editarea/exemples/exemple_full.html
is more usable for the OP.
You know about WYSIWYG editors?
I use http://www.tinymce.com/
On google you can find more and also create your own with jQuery and others.
To import a file into the textarea you could either:
You will also have to "encode html entities" inside of your text area, otherwise they will display as HTML elements, not the source code.
And to enable syntax highlighting for the code see CodeMirror or search the web for "HTML Syntax Highlighter"
As Lucas said, I'm pretty sure that you can't have HTML displaying as HTML (e.g., <b>hello</b
displaying bold) inside a textarea element. You will need some sort of 3rd party editor (see this). To include a file in PHP, use $content = file_get_contents("path_to_the_file");
and then do echo($content);
wherever you want the file contents to appear. You will also probably want to consider this for XSS attacks if you are having a dynamic system where people can upload their own files or if you want to display the <
and >
signs without making invalid HTML.
You cannot highlight codes in a TEXTAREA. TextArea elements only accept plain text so far.
The trick is to create a DIV and highlight the text within the DIV and place the DIV above the TEXTAREA tag. This can be done either by using TinyMCE or FCKEditor or any similar WYSIWYG editor.
As for importing the code into the page, you will need a programming language (like PHP) to open the file and fetch its contents. Make sure, though, to import only what is between the body tags.