Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3640
  • Last Modified:

Convert URL parameters to UTF-8 encoding?


I need some help to encode a url from Chinese characters to one which is universal.
As an example the URL would be: http://www.mysite.com/folder/CHINESE CHARACTERS HERE 001.JPG

It wont allow me to post the exact url here beacuse the Chinese characters arent recognized but you should get the idea

This script here:
Is nearly perfect:

when you enter:
http://www.mysite.com/folder/CHINESE CHARACTERS HERE 001.JPG
it returns:

However the code on this script relies on an external .js file and i need it all in one document, e.g. using javascript tags in the header
<script type="text/javascript">

Also this script converts the "http://" to "http%3A//" which is not correct...

So can some kind person please post a full code example of how i convert the external .js file to be in the html header between the javascript tags and add in some code to stop the http at the beginning being converted.

Many thanks in advance.
1 Solution
You can have the external .js in the same code. Open the .js and copy the code inside the curreent page. Without the .js code I cannot help you.
The answer is so much simpler that it looks. There is already a Javascript function that does de job for you, although it converts the ":" to "%3A, but you can convert it back by replacing it inside the original string:
<script language="javascript">
function URLcode(str){
for testing purposes:
alert(URLcode("http://domain.com/!#*=Hello Everybody"));

And, UTF-8 is a way of coding a Unicode Wide character. URLEncode is a way to encode a byte in a hexadecimal manner. UTF-8 and URL coding are not the same from far.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now