在PHP中,可以使用以下函数来进行URL编码和解码:
$url = "https://www.example.com/?q=php 中文";
$encoded_url = urlencode($url);
echo $encoded_url; // 输出 https%3A%2F%2Fwww.example.com%2F%3Fq%3Dphp+%E4%B8%AD%E6%96%87
$encoded_url = "https%3A%2F%2Fwww.example.com%2F%3Fq%3Dphp+%E4%B8%AD%E6%96%87";
$decoded_url = urldecode($encoded_url);
echo $decoded_url; // 输出 https://www.example.com/?q=php 中文
$url = "https://www.example.com/?q=php 中文";
$encoded_url = rawurlencode($url);
echo $encoded_url; // 输出 https%3A%2F%2Fwww.example.com%2F%3Fq%3Dphp%20%E4%B8%AD%E6%96%87
$encoded_url = "https%3A%2F%2Fwww.example.com%2F%3Fq%3Dphp%20%E4%B8%AD%E6%96%87";
$decoded_url = rawurldecode($encoded_url);
echo $decoded_url; // 输出 https://www.example.com/?q=php 中文