PHP URL函数

PHP rawurldecode() 函数对 URL 编码的字符串进行解码。它返回一个字符串,其中百分号 (%) 后跟两个十六进制数字的序列替换为文字字符。

注意:此函数执行以下操作:不像 urldecode() 函数那样将加号 + 解码为空格。

语法

rawurldecode(string) 

参数

string必填。 指定要解码的 URL。

返回值

以字符串形式返回解码后的 URL。

示例:

下面的示例显示了 rawurldecode() 函数的用法。

<?php
$str = "Yxjc123%20an%20online%20learning%20portal";
$decoded_str = rawurldecode($str);

//显示解码后的字符串
echo $decoded_str;
?> 

上述代码的输出将是:

Yxjc123 an online learning portal 

示例:

再考虑一个示例,它显示了字符串的编码方式以及已解码。

<?php
$str1 = "Yxjc123 an online learning portal";
$encoded_str1 = rawurlencode($str1);

echo "The string is: $str1 \n";
echo "Encoded string: $encoded_str1 \n";

$str2 = "Yxjc123%20an%20online%20learning%20portal";
$decoded_str2 = rawurldecode($str2);

echo "\nThe string is: $str2 \n";
echo "Decoded string: $decoded_str2 \n";
?> 

上述代码的输出将是:

The string is: Yxjc123 an online learning portal 
Encoded string: Yxjc123%20an%20online%20learning%20portal 

The string is: Yxjc123%20an%20online%20learning%20portal 
Decoded string: Yxjc123 an online learning portal