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 += {'<':'<', '>':'>', '&':'&', '\"':'"', '\'':''', '-':'-', '/':'/', '=':'=', '!':'!', '(':'(', ')':')', '[':'[', ']':']', '{':'{', '}':'}', '\n':' '}[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.
loading...
loading...
| Print article | This entry was posted by Tom on April 16, 2009 at 7:17 pm, and is filed under Computer Programming. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |


