EditLive! 9 Documentation : Encoding Content for Use with EditLive!

When working with content that is to be placed in EditLive!, it must be ensured that the relevant content is URL encoded before it is used. This encoding is required so that the content can be used with the JavaScript used to instantiate EditLive!.

When instantiating EditLive! with the ASP or ASP.NET load-time properties, the content placed in the Style, Content, Document and Body properties is automatically URL encoded using the appropriate method.

It is recommended that this URL encoding operation be performed on the server side through the use of the appropriate server-side scripting function. It is possible to use the JavaScript encodeURIComponent function; this is, however, not recommended as these functions are not certain to provide correct URL encoding across all browsers. JavaScript's encodeURIComponent function also encodes content using the UTF-8 character set, which may conflict with the Character Sets Supported for use with EditLive!.

Client-side URL Encoding Functions

The following functions provide URL encoding for strings on the client-side. Where possible, it is recommended that a server-side URL encoding function be used as the exact behavior of these functions is browser dependant.

JavaScript

JavaScript provides the encodeURIComponent function. The encodeURIComponent function will encode content as UTF-8 characters. 

This may conflict with the Character Sets specified for use with EditLive!.

Server-side URL Encoding Functions

Most scripting languages provide a function to URL encode strings. The following section defines URL encoding functions which can be used with several common server side scripting languages.

ASP

The URL encoding function which can be using in ASP is Server.URLEncode. This can be used in the following manner:

Server.URLEncode("this string will be url encoded")
ASP.NET (C#)

The URL encoding function which can be used in ASP.NET is HttpUtility.UrlEncode. This class is part of the System.Web package. The function can be used in the following manner, with the correct "using" statement:

using System.Web; ...
   HttpUtility.UrlEncode("this string will be url encoded");
JSP (Java)

The URL encoding method which can be used in JSP and Java classes is the URLEncoder.encode() method. The URLEncoder class can be found in the java.net package. The function can be used in the following manner and the relevant import statements must be included:

import java.net.URLEncoder; ...
URLEncoder.encode("this string will be url encoded");
PHP

When using the PHP URL encoding functions, it is important to use the rawurlencode function as opposed to the urlencode function. The function can be used in the following manner:

rawurlencode('this string will be url encoded');

It is important to note that the urlencode function provides different functionality to the rawurlencode function. The urlencode function encodes spaces as + symbols which may cause errors with EditLive!.

ColdFusion

When implementing an EditLive! integration with ColdFusion the URL encoding function which should be used is URLEncodedFormat. This function can be used in the following way:

urlencodedformat("this string will be url encoded");
Perl

Perl does not include a URL Encode function as part of the standard libraries; developers must write their own. This can be achieved through the use of regular expressions. The following code gives an example on how this may be achieved:

#!/usr/bin/perl $encodeString = "this string will be url encoded";
$encodeString = ~s/([Encoding Content for Use with EditLive!^A-Za-z0-9_\-.]/uc;
sprintf("%%%02x",ord($1))/eg;

Encoding with International Characters

When encoding content for use with EditLive! that contains international characters it may be necessary to specify a character set for use with the server-side encoding method. Please consult your programming language reference for more information on how to specify a character set. It is recommended that UTF-8 character encoding is used in these circumstances, though other character encodings may also be used.

Symptoms of using an incorrect character encoding method with EditLive! are:

  • The □ appears on entering text. This symbol means the current font set being used does not support the character entered.
  • The symbol ? appears on entering text. This means character encoding has been corrupted due to an incorrect character encoding method.

Example
A document's character set has been defined as UTF-8. The body of the document has been set using the URLEncoder.encode() Java function in a JSP page, with the ISO2022JP charset. Because symbols created by the ISO02022JP encoding method are not supported by UTF-8, encoding errors will occur.

The methods available to change the character encoding method used by EditLive! are depicted in the Specifying Character Set article.

See Also