编码转换提交,从GBK页面向UTF8页面POST数据,或从UTF8页面向GBK页面POST数据

最近做支付接口时遇到一种情况,那就是:我们网站A是GBK编码的,支付平台B是UTF8编码的,我需要从A向B网站POST数据,由于编码不一致,就会出现乱码的情况。这样我们就需要在中间加一个跳转页,实现这个编码转换的过程。将下面代码拷贝到PHP文件中,并存储为UTF8编码的文件。


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
正在跳转到支付平台........
<?
echo "<form action='".urldecode($_GET['to_url'])."' method='post' id='theform'>";
foreach($_POST as $key =>$value){
    echo '<input type="hidden" name="'.$key.'" value="'.iconv('GBK','UTF-8',$value).'" />';
}
echo "</form>";
?>
</body>
<script>
document.getElementById('theform').submit();
</script>

</html>

当然,把上面代码中GBK换成UTF-8,UTF-8换成GBK,然后存储为GBK编码的PHP文件,就可以做为从UTF-8页面向GBK页面POST的中转页面。


( ! ) Warning: Missing argument 1 for cwppos_show_review(), called in /data/www/enjoyphp/wp-content/themes/flat/content-single.php on line 29 and defined in /data/www/enjoyphp/wp-content/plugins/wp-product-review/includes/legacy.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0000354984{main}( ).../index.php:0
20.0001355272require( '/data/www/enjoyphp/wp-blog-header.php' ).../index.php:17
30.169410152520require_once( '/data/www/enjoyphp/wp-includes/template-loader.php' ).../wp-blog-header.php:19
40.170610223664include( '/data/www/enjoyphp/wp-content/themes/flat/single.php' ).../template-loader.php:74
50.254110796368get_template_part( ).../single.php:5
60.254110796888locate_template( ).../general-template.php:167
70.254210796984load_template( ).../template.php:643
80.254210797368require( '/data/www/enjoyphp/wp-content/themes/flat/content-single.php' ).../template.php:686
90.259410782480cwppos_show_review( ).../content-single.php:29

1 评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注