如何在Shift_JIS上的urlencode在PHP上?

时间:2018-10-05 09:08:59

标签: php character-encoding encode urlencode

您好,我有此URL(网站字符集为Shift_JIS)

shop_search.php?pref=北海道**

,但是在尝试访问

之前应将其转换为此
shop_search/shop_search.php?pref=%96k%8AC%93%B9**

我尝试了这个但没有成功:

  • mb_convert_encoding($ url,“ UTF-8”,“ Shift_JIS”)然后对其进行urlencoding
  • 使用urlencoding将其编码为UTF-8,而不是Shift_JIS
  • rawrlencode与urlencode相同

1 个答案:

答案 0 :(得分:1)

您必须从SJIS转换为UTF-8,然后对其进行url编码,而不是从UTF-8转换为SJIS,对吗?

正如您所说的“网站字符集为Shift_JIS”。

<?php
$var = "北海道**";

$new = mb_convert_encoding($var, "SJIS", "UTF-8");

echo urlencode($new); // outputs %96k%8AC%93%B9%2A%2A
?>