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

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

Convert URL parameters to UTF-8 encoding?

Hi,

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

-Edit-
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:
http://javascript.internet.com/navigation/url-decode-encode.html
Is nearly perfect:

when you enter:
http://www.mysite.com/folder/CHINESE CHARACTERS HERE 001.JPG
it returns:
http%3A//www.mysite.com/folder/%E7%85%A7%E7%89%87%20001.JPG

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">
<!--
//-->
</script>

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.
0
whiteboyracer48
Asked:
whiteboyracer48
1 Solution
 
thenoneCommented:
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.
0
 
palurdoCommented:
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){
      str=escape(str);
      str=str.replace("%3A",":");
return(str);
}
</script>
for testing purposes:
<script>
alert(URLcode("http://domain.com/!#*=Hello Everybody"));
</script>

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.
0

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