halo_wordpress

HTML Encoder

Have you ever wanted to encode your html to make it show up inside of um say wordpress post and not be ran through html scripting? Well here yah go: This will output that for you!
(Allthough this will not work in IE) Working on a solution for that (try this)

Source Text :


With Entities Encoded: (Click to Select All)

What it looks like in PRE tags:


Want this code?
If you just copy/paste code below to webpage it should work.
Javascript code with script tags to put in html code/webpage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<script type="text/javascript">
//<![CDATA[ 
 
function $(id){ return document.getElementById(id) }
 
function encode_entities(s){
  var result = '';
  for (var i = 0; i < s.length; i++){
    var c = s.charAt(i);
    result += {'<':'&#60;', '>':'&#62;', '&':'&#38;', '\"':'&#34;', '\'':'&#39;', '-':'&#45;', '/':'&#47;', '=':'&#61;', '!':'&#33;', '(':'&#40;', ')':'&#41;', '[':'&#91;', ']':'&#93;', '{':'&#123;', '}':'&#125;', '\n':'&#13;'}[c] || c;
  }
  return result;
}
function do_encode(e){
  $('pre').innerHTML = $('dst').value = encode_entities(e.value)
}
 
//]]> 
 
</script>

Make sure to put htmlencoder_nojstags.js file on your server and don’t just copy paste the below code unless you add: <script type="text/javascript"></script> tags. You also have to add the forms portion of the code too.

note: Javascript code without script tags are to put in *.js file

Forms file/html

1
2
3
4
5
6
7
8
Source Text :
<div id="form">
<textarea cols="80" rows="16" onkeyup="do_encode(this)" onchange="do_encode(this)"></textarea>
With Entities Encoded: (Click to Select All)
<textarea id="dst" cols="80" rows="16" onfocus="this.select()" onclick="this.select()"></textarea>
What it looks like in PRE tags: 
<pre id="pre"></pre> 
</div>

Courtesy of Dan Kogai’s HTML Encoder with a little bit of modification.

GD Star Rating
loading...
GD Star Rating
loading...
HTML Encoder , 9.0 out of 10 based on 2 ratings

Leave a Reply

Your email address will not be published. Required fields are marked *