Enter your email address:

Delivered by FeedBurner


Sign up to receive a reply:

Powered by MT-Notifier

user-pic

HTML Encoder for blogs that share HTML code often

Vote 0 Votes

When you're trying to share code in a blog entry, you might run into one big problem: HTML code is rendered as code, not text. To get around this, I've built a converter that turns HTML code into something that will render as text.

To see it in action, go to http://blog.lib.umn.edu/heinz062/uthink-forum/html-encoder.php

Create a new index template, call it "HTML Encoder", then click on Template Options to change the output file to "html-encoder.php".

<form id="create-entry-form" method="post"> <div id="entry-body-field" class="field-top-label field pkg "> <div class="field-inner"> <div class="field-header"> <label id="entry-body-label" for="entry-body">HTML Encoder (skip if you won't be adding code to your entry)</label> </div> <div class="field-content "> <textarea id="entry-body" class="ta" name="htmlencode" rows="7" cols="50"></textarea> </div> </div> </div>

<input type="submit" name="Encode" value="Encode" />
</form>

<?php
$htmlencode = $_POST['htmlencode'];
if($htmlencode){
$htmlencode = htmlentities($htmlencode);
$htmlencode = htmlentities($htmlencode);//encode twice
echo "<form id=\"create-entry-form\">";
echo " <div id=\"entry-body-field\" class=\"field-top-label field pkg \">
<div class=\"field-inner\">
<div class=\"field-header\">
<label id=\"entry-body-label\" for=\"entry-body\">Encoded HTML (copy-paste into the Body)</label>
</div>
<div class=\"field-content \">
<textarea id=\"entry-body\" class=\"ta\" rows=\"7\" cols=\"50\"><div class=\"htmlcode\">$htmlencode</div></textarea>
</div>
</div>
</div>
";//end echo
echo "</form>";

}

?>

Now link to it somewhere on your blog (like your Entry Form template) using code like this:

<p>If you will be using HTML code, use my <FORM name="myform"><INPUT TYPE="button" value="HTML Encoder" onClick="new_win()" /></FORM> so that it will display properly.</p>

Just remember that form tags within form tags don't work very well. I also defined a class in the stylesheet for "htmlcode", so that code is separated from other entry content by a grey background.

.htmlcode { font-family:Courier, serif; background-color:#F5F5F5; border-color:#DDDDDD; padding:5px 25px 5px 25px }

Add a Reply

Forum Groups

Classic Blogs and General Info

29 42

Last Topic: Can I use PHP code in my blog? by Charlie Heinz on Jan 9, 2012

Discussions

Q&A

Be the first to post a topic in this forum

Blogging Principles

Be the first to post a topic in this forum

Other Template Sets

Community Blogs

Be the first to post a topic in this forum

Community Forums

Be the first to post a topic in this forum

Widget Marketplace