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

mac2026-06-19  5

使用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");
最新回复(0)