To convert a URL to GBK encoding in PHP, you can use the urlencode() function along with the mb_convert_encoding() function. Here's an example:
$url = "https://example.com/你好";
$encodedUrl = urlencode($url);
$gbkUrl = mb_convert_encoding($encodedUrl, 'GBK', 'UTF-8');
echo $gbkUrl;
In this example, the URL "https://example.com/你好" is first encoded using urlencode(), which replaces non-ASCII characters with percent-encoded values. Then, the mb_convert_encoding() function is used to convert the encoded URL from UTF-8 to GBK encoding.
Note that the mb_convert_encoding() function requires the mbstring extension to be enabled in PHP.
上一篇:php 入栈abcde
下一篇:php 设置访问超时
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站