开发者

Turn URL encoded string into UTF-8

Yesterday I faced problem about getting some Unicode strings from URL. Actually I use CodeIgniter and the URL segments will be passed into controller/function(parameters). I don't know is it the CI changes the encoding or it's something else. I have the right encoding in my HTML page in the content and in the address bar till I get those Unicode segments.

For example:

localhost/df-gamez/news/افتتاح-جدید-سایت-تیم-دریم-فکتوری

The last segment is perisan characters which is under UTF-8. It's present correctly in everywhere but when I get it in my code It will turn to something like this:

%d8%a7%d9%81%d8%aa%d8%aa%d8%a7%d8%ad-%d8%b3%d8%开发者_C百科a7%db%8c%d8%aa-%d8%ac%d8%af%db%8c%d8%af-
%d8%aa%db%8c%d9%85-%d8%af%d8%b1%db%8c%d9%85-%d9%81%da%a9%d8%aa%d9%88%d8%b1%db%8c

I tried to change it to UTF-8 with mb_encode but it didn't. Both my HTML page and Controller file are formatted as UTF-8 Without BOM.

Peace Out!


Use urldecode function to decode.

echo urldecode("%d8%a7%d9%81%d8%aa%d8%aa%d8%a7%d8%ad-%d8%b3%d8%a7%db%8c%d8%aa-%d8%ac%d8%af%db%8c%d8%af-%d8%aa%db%8c%d9%85-%d8%af%d8%b1%db%8c%d9%85-%d9%81%da%a9%d8%aa%d9%88%d8%b1%db%8c");

will give you افتتاح-سایت-جدید-تیم-دریم-فکتوری

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜