I have a script which generates some HTML. I like having the HTML print to a <textarea> since it's easy to copy/paste from.

The problem is the script outputs raw HTML, but the obviously, something like:

<script LANGUAGE=javascript type="text/javascript"><!--
testdata = '&#114;&#111;&#098;&#101;&#114;&#116;';
 //--></SCRIPT>

can't just be inserted between <textarea> as it's not urlencoded... but when I do URL encode, it removes spacing and all that fun stuff.

So what's the most efficient (quickest) way to have it encode what needs to be encoded, so that it outputs to the text box and looks good?

    Take a look at htmlentities. urlencode() should only be used when you're adding stuff to a URL. For example, when you want to add "this is some !#!@# string" as the query string for index.php, you'd send the string through urlencode() first, before appending it.

    Diego

      I got this display correctly between <textarea> and </textarea>:

      <script LANGUAGE=javascript type="text/javascript"><!--testdata = '&#114;&#111;&#098;&#101;&#114;&#116;';
      //--></SCRIPT>

      But anyway, you may try the PHP functions
      htmlspecialchars ()
      htmlentities()

      Have a nice day!!

        Write a Reply...