Editing HTML in a form?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I want to build a very basic online text editor, to allow customers to
modify their own sites' html content using a simple form with textarea

I read the HTML file like so:


  function EditText ($filepath)
    if (!$file = file($filepath)) return false;
    foreach ($file as $line) {
      $value .= $line;       // contains all text in file when done
    $html = "<html><head><title>Editor</title></head>
               <form method='post' action='processtext.php'>
               <textarea rows='40' cols='80' name='txt' value='$value'>
               <input type='submit'>
    echo $html;
    return true;

  EditText ('/sample/index.html');

The problem comes when the parsed file containing html elements itself
is echoed to the browser. In itself, PHP does what it's asked, but all
browsers I tried choke on the contents of the TEXTAREA field. Best
example may be: try parsing the file containing the script itself, it
becomes a real mess.

I tried htmlspecialchars, this did not fix it. I tried addslashes to
only escape the quotes in the parsed file, also no success.

I saw one example online where 'they' preg_replaced about every possible
(x)html and php syntax element, resulting in an immensely large and slow
script. Can't imagine that's the proper way forward.

If at all possible I'd like to stay away from Javascript. Any idea if
this is a realistic approach? Are there any useable scripts available? I
searched google a lot, but I keep ending up at sites that offer html or
php editors for local use, not in a browser.

Thanks for any good tips!

Re: Editing HTML in a form?

Quoted text here. Click to load it

I haven't examined too closely how Peter does it, but FacileForms
allows one to put HTML & PHP in textareas that then get stored on the

You could download that package and take a look at the various classes
to see how it's done.

Re: Editing HTML in a form?

Captain Paralytic wrote:
Quoted text here. Click to load it
Hadn't seen Facile forms yet. Looks like a rather big package, but
perhaps I can find the details I'm after. Tried a similar approach with
my provider's cms package built-in text editor, but got lost completely
in its messy hardly documented code.

I'll let you know if/when I find something useful there!
Thanks for your input Captain!


Re: Editing HTML in a form?

Schraalhans Keukenmeester wrote:
Quoted text here. Click to load it

htmlentities() is probably what you're looking for:

<textarea name='txt'>".htmlentities($value)."</textarea>

Also note the correction of the textarea content format!



Re: Editing HTML in a form?

Ian Taylor wrote:
Quoted text here. Click to load it
Gee, how did I miss that. Thx. Must have been late when I put this
together. Thanks a bunch! Duh! Kindergarten stuff. Why didn't I learn a
skill ....  ;-) Great, now I'm done. Works for me like this!


Re: Editing HTML in a form?

On Thu, 15 Feb 2007 17:35:21 +0100, Schraalhans Keukenmeester  =

Quoted text here. Click to load it

Unlike other HTML element, this should be:

Also, you might want to look into stuff like TinyMCE etc.
-- =

Rik Wasmus

Site Timeline