Home  >  Article  >  Backend Development  >  php 怎么把得到的文件名编码换一下?

php 怎么把得到的文件名编码换一下?

WBOY
WBOYOriginal
2016-06-06 20:07:211081browse

<code><?php $path="C:/AppServ/www/YB-PHP";
$d=opendir($path);//把目录打开为资源
while( $a = readdir($d))
{
    echo $a."<br>";
}
</code>

echo :

<code>.
..
.project
1.jpg
br_ .php
class
example
file_example
mysql-example
path_demo
PDO-example
PDO-PHP-HTML
PHP-FORM
ShiYan
xdl
xsphp
�½��ļ���</code>

这个 �½��ļ��� 就是 新建文件夹..
怎么换换编码?

回复内容:

<code><?php $path="C:/AppServ/www/YB-PHP";
$d=opendir($path);//把目录打开为资源
while( $a = readdir($d))
{
    echo $a."<br>";
}
</code>

echo :

<code>.
..
.project
1.jpg
br_ .php
class
example
file_example
mysql-example
path_demo
PDO-example
PDO-PHP-HTML
PHP-FORM
ShiYan
xdl
xsphp
�½��ļ���</code>

这个 �½��ļ��� 就是 新建文件夹..
怎么换换编码?

<code><?php /**
 * 关注微信公众号:phpgod(PHP技术大全,每日精彩技术分享).
 */
header("Content-Type:text/html;charset=GB2312");

$directoryResource = opendir(".");
while($directory = readdir($directoryResource)){
    echo $directory."<br/>";
}</code>

<code>$content = iconv("GBK", "UTF-8", $content); 
$content = mb_convert_encoding($content, "UTF-8","GBK");

可以使用这个PHP函数转码,但是mb_convert_encoding()这个函数,需要开启php.ini的PHP扩展</code>

header设置一下

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn