php中echo输出dir命令时出现中文乱码解决方法

使用php中echo输出dir命令时出现如下情况
������ D �еľ��� ��� �������к��� C10-092 D:\Apache24\htdocs ��Ŀ¼ 2019/10/30 21:14
. 2019/10/30 21:14
… 2015/01/12 15:40 4,286 apacheaus.ico 2019/10/30 21:15 29 index .php - ���� (2).html 2019/11/02 15:39 50 index .php - ����.hml 2019/10/21 12:38 22 indx .php.html 4 ���ļ� 4,387 �ֽ� 2 ��Ŀ¼ 788,3,320,896 �����ֽ�

因为在windows操作系统下, o u t p u t = ‘ d i r ‘ 得 到 的 output=`dir`得到的 output=diroutput编码为gb2312,应使用iconv转换才能在utf-8编码下正常显示。

<?php $output = `dir `; $output = iconv("GB2312","UTF-8","$output"); echo $output; ?>

正常显示
驱动器 D 中的卷是 最大 卷的序列号是 C10-292 D:\Apache24\htdocs 的目录 2019/10/30 21:14
. 2019/10/30 21:14
… 2015/01/12 15:40 4,286 apachehaus.ico 2019/10/30 21:15 29 index .php - 副本 (2).html 2019/11/02 15:42 94 index .php - 副本.html 2019/10/21 12:38 22 index .php.html 4 个文件 4,431 字节 2 个目录 788,314,320,896 可用字节
另外也可以在代码前加上

header("Content-type:text/html;charset=gbk");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值