Results 1 to 4 of 4
Aug 19, 2008, 20:54 #1
url = "http://www.website.com/foo.php?q=" + escape(getElementById("keyword").value)
so as to do an AJAX query...
all goes well until I tried using Chinese characters and French characters.
For example, if I enter 和記 into the search box, then that part of the url becomes foo.php?q=%u548C% u8A18 (no space between % and u, but i need to enter a space so that the webpage won't goof up)
this format % u548C is quite rarely seen... as opposed to %E5%92%8C%E8%A8%98 which usually the browser generates as UTF-8. And it is different from 和 which is for html also.
If i use it, then I get the UTF-8 and it works well in PHP. Otherwise, I will need to convert % u548C back to UTF-8 before processing it.
The same goes for French, if the word véritable is entered into the search box, then escape() will give v%E9ritable while encodeURI() or encodeURIComponent() will give v%C3%A9ritable which is UTF-8, and it works well since it is consistently UTF-8 (no need to deal with % u548C or %E9 as two different cases) (the final task is actually to get info from youtube using that search string, and must work well when the search string has space, single quote, double quote, and international characters).
Aug 19, 2008, 22:19 #2
- Join Date
- Aug 2000
- Philadephia, PA
- 1 Post(s)
- 0 Thread(s)
You've already discovered the solution, yes.
escape() is only safe for characters in the ASCII range
encodeURI and encodeURIComponent are safe for UTF-8Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
Aug 19, 2008, 22:53 #3
i realize when i type
don't say goodbye
then the URL will contain
then the return value is
Aug 20, 2008, 01:12 #4
- Join Date
- Sep 2005
- Sydney, NSW, Australia
- 25 Post(s)
- 1 Thread(s)
There is no built in method for doing that, you would need to build your own. A one line regular expression should be able to do it provided that you can organise all of the map from/to values.