Convert URL parameters to UTF-8 encoding?

whiteboyracer48 used Ask the Experts™

I need some help to encode a url from Chinese characters to one which is universal.
As an example the URL would be: 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: 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.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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("!#*=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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start Today