在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 中文