Home > Web Front-end > JS Tutorial > body text

Questions about JAVASCRIPT urldecode URL decoding_javascript skills

WBOY
Release: 2016-05-16 17:57:32
Original
1841 people have browsed it

At this time, encodeURIComponent and decodeURIComponent appeared, which can completely encode and decode URLs. However, when encountering partial transcoding used by search engines, for example, it is difficult to find the door. No problem, PHP officially has a solution:

Copy code The code is as follows:

decodeURIComponent((str '').replace(/ / g, ' '));

It can perfectly decode the address of the search engine, because the search engine is only used to transcoding "spaces". Forgot to mention that I am also used to transcoding Chinese. . .
Then all the above solutions collapsed when encountering Chinese. Yes, I also collapsed. It was partially encoded and it was Chinese. . This makes me feel so embarrassed. . .
It’s okay to look it up for a long time, so I won’t say too much so you understand. . .
Copy code The code is as follows:




This is only for those that support VB Browser support. . . For example, FF does not support it. . .
Why use VB? Because methods like str2asc and asc2str cannot be satisfied by JS. . . Below I simulated two JS methods, which do not seem to be valid for all Chinese languages. .
Copy code The code is as follows:

function str2asc(str){
return str. charCodeAt(0).toString(16);
}
function asc2str(str){
return String.fromCharCode(str);
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template