php - Convert unicode URL to ASCII -
i'm writing php application accepts url user, , processes making calls binaries system()
*. however, avoid many complications arise this, i'm trying convert url, may contain unicode characters, ascii characters.
let's have following url:
https://täst.de:8118/news/zh-cn/新闻动态/2015/
here 2 parts need dealt with: hostname , path.
- for hostname, can call
idn_to_ascii()
. - however, can't call
urlencode()
on path, each of characters need remain unmodified converted (e.g.news/zh-cn/新闻动态/2015/ -> news%2fzh-cn%2f%e6%96%b0%e9%97%bb%e5%8a%a8%e6%80%81%2f2015%2f
opposednews/zh-cn/%e6%96%b0%e9%97%bb%e5%8a%a8%e6%80%81/2015/
).
how should approach problem?
*i'd rather not deal system()
calls , resulting complexity, given functionality available calling binaries, unfortunately have no choice.
split url /
urlencode()
part put together
$url = explode("/", $url); $url[2] = idn_to_ascii($url[2]); $url[5] = urlencode($url[5]); $url = join("/", $url);
Comments
Post a Comment