encodeURI / decodeURI / escape 와 unescape를 대채할 수 있는 훌륭한 함수 > script

본문 바로가기
사이트 내 전체검색

script

encodeURI / decodeURI / escape 와 unescape를 대채할 수 있는 훌륭한 함수

페이지 정보

작성자 서방님 댓글 0건 조회 90회 작성일 07-08-08 15:52

본문

 

http://www.ephox.com/developers/editliveforjava/v40/html/articles_encoding.html

 

Encoding Content for Use with EditLive! for Java

Introduction

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

It should be noted that when instantiating EditLive! for Java with the ASP, ASP .NET or J2EE SDKs the content placed in the Style, Document and Body properties is automatically URL encoded using the appropriate URL encoding method.

It is recommended that when URL encoding content that this operation be performed on the server side through the use of the appropriate server side scripting function. It is possible to use the JavaScript escape or encodeURI functions however this is not recommended as these functions are not certain to provide correct URL encoding across all browsers.

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 has two URL encoding functions available; escape and encodeURI. The functionality of these two functions is browser dependant.

Although it is recommended that a server-side URL encoding function is used, in cases where client-side JavaScript must be used the encodeURI function should be used. The encodeURI function will encode content as UTF-8 characters.

Example 4.6. URL Encoding with JavaScript encodeURI

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:

Example 4.7. URL Encoding with ASP

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:

Example 4.8. URL Encoding with ASP.NET (C#)

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:

Example 4.9. URL Encoding with JSP

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:

Example 4.10. URL Encoding with PHP

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

Note

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! for Java.

ColdFusion

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

Example 4.11. URL Encoding with ColdFusion

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

Perl

Perl does not include a URL Encode function as part of the standard libraries and therefore 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:

Example 4.12. URL Encoding with a Regular Expression in Perl

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

Encoding with International Characters

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

A <meta> element specifying the character encoding should also be added to the EditLive! for Java configuration file. The following is an example <meta> tag specifying the UTF-8 character set:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Summary

Content which is to be added to EditLive! for Java should be URL encoded. The methods listed above can be used to URL encode content with several popular scripting languages. The JavaScript encodeURI function can also be used, however, this is not recommended as the encoding provided by this function does not comply with URL encoding in all browsers.

댓글목록

등록된 댓글이 없습니다.

Total 846건 37 페이지
게시물 검색

회원로그인

접속자집계

오늘
62
어제
302
최대
1,347
전체
155,123
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.