Adding code to your website without it getting parsedSometimes you want to be able to add code to your website, but the problem is that when you add it, the web browser always parses it as HTML and the formatting doesn't show up correctly. For all you programming websites, or anyone else who just wants to post some HTML or other code on their website, there are a few ways you can do it. If you're using a PHP site, you can simply use the htmlentities function. This will replace all HTML special characters with their equivalent HTML entities. So, < becomes <. You could also manually replace the special characters (Good reference here), but that's really time consuming. The only other option I know about is to put the <textarea> tags around the HTML code you want to display. Like this: As you can see, all the HTML tags in the textarea show up for you to see. Define the size of a text area using the "cols" and "rows" parameters. Textarea controls default to allow input. If you do not want users to be able to change the contents, you can use the "readonly" parameter. The textarea above is defined as <textarea cols=50 rows=3 readonly>. The "name" parameter would also be required to use textarea for data input. The official textarea standards writeup can be found here. If anyone else has any other methods for posting HTML or other code to your site, please email us at comments@techbytes.ca. Author: DPAK Created: Sep 20 2005 (last modified Sep 23 2005) Categories: Website Development TechByte #20 Warning: By visiting this site and/or by using any information contained herein, you agree to the Techbytes.ca terms of use. Add a comment about this TechByteIf you wish to add a comment regarding this TechByte, please use the form below. Please note that by submitting comments using this form you are allowing all of the information submitted to be visible on this website. Any comments submitted using this form will only be shown on the website if they are approved by the administrators of this site. IF APPROVED, COMMENTS MAY TAKE SEVERAL DAYS TO BE POSTED. Other TechBytes: |
|

