简体   繁体   English

PHP将%符号从URL转换为实际URL?

[英]PHP Convert % symbols from URL to actual url?

Ive got a script to handle some of my game files, For example the URL of them is like this: 我有一个脚本来处理一些游戏文件,例如,它们的URL是这样的:

 3%2C 2%2C 1%2C Smurf%21 My First Racing Game

Where the actual name should be: 实际名称应为:

3, 2, 1, Smurf! My First Racing Game

Is there a function to convert all them % things into the actual symbol they should be? 是否有一个功能可以将所有%的事物转换为它们应为的实际符号?

Or do i just have to str_replace them all? 还是我只需要str_replace他们全部?

Thanks 谢谢

What you have is a URL-encoded string. 您拥有的是URL编码的字符串。 You can use urldecode() to decode it: 您可以使用urldecode()进行解码:

$str = '3%2C 2%2C 1%2C Smurf%21 My First Racing Game';
echo urldecode($str); // 3, 2, 1, Smurf! My First Racing Game

php has a built in function for url decoding: php具有内置的URL解码功能:

urldecode($yourUrlString)

http://www.php.net/manual/en/function.urldecode.php http://www.php.net/manual/zh/function.urldecode.php

Note: if Your string is also UTF-8 encoded . 注意:如果您的字符串也是UTF-8编码的。 This will work: 这将起作用:

echo utf8_decode(urldecode(your url string));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM