Removing the "%" encoding in URL string
I am attempting to open a page with window.open
and it's开发者_如何转开发 not working. The path shown is like xyz/a%20b%20c%20.pdf
, but it is supposed to be xyz/abc.pdf
. If I remove the %
and 20
manually, it works, how can I remove these characters using PHP?
Use urldecode:
(PHP 4, PHP 5) urldecode — Decodes URL-encoded string
Description
string urldecode (
string $str
) Decodes any %## encoding in the given string. Plus symbols ('+') are decoded to a space character.
Example
echo urldecode('xyz/a%20b%20c%20.pdf');
This is known as URL Encoding. You need to decode the string. If you are using jQuery you should check out the URL Encode plug in.
You need to urldecode (as stated above).
However, you say that you can remove the %20 and it will work. I would say you need them, they decode to spaces. Check it out using this online url decoder:
http://www.convertstring.com/EncodeDecode/UrlDecode
it decodes to:
xyz/a b c .pdf
not
xyz/abc.pdf
精彩评论