Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
输出到xml的带有特殊字符的文件名的php列表_Php_Xml_Utf 8 - Fatal编程技术网

输出到xml的带有特殊字符的文件名的php列表

输出到xml的带有特殊字符的文件名的php列表,php,xml,utf-8,Php,Xml,Utf 8,提醒:我对php非常缺乏经验 我试图读取服务器上文件列表的名称,并用这些名称创建一个XML文件。其中一些具有外语字符,这会在XML创建过程中产生问题 在四处搜索之后,我意识到我可能需要使用htmlspecialchars或rawurlencode,但我一直无法让它们正常工作 下面的代码是根据我在网上找到的代码构建的。这样做没有什么特别的原因,除了不知道更好 $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterato

提醒:我对php非常缺乏经验

我试图读取服务器上文件列表的名称,并用这些名称创建一个XML文件。其中一些具有外语字符,这会在XML创建过程中产生问题

在四处搜索之后,我意识到我可能需要使用
htmlspecialchars
rawurlencode
,但我一直无法让它们正常工作

下面的代码是根据我在网上找到的代码构建的。这样做没有什么特别的原因,除了不知道更好

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath($_SERVER['DOCUMENT_ROOT'])), RecursiveIteratorIterator::SELF_FIRST);

header("Content-Type: text/xml;");
echo '<?xml version="1.0" encoding="UTF-8"?><list>';
foreach($objects as $name){

    echo '<file><loc>'.$name.fileName.'</loc><lastmod>'.date('Y-m-d',filemtime($name)).'</lastmod></file>';
}
echo '</list>'; 

您还可以尝试使用utf8_encode(),看看是否有帮助。注意:您需要这样做才能尝试:echo'.utf8_encode($name.fileName)。'.date('Y-m-d',filemtime($name))';这并不能解决问题显然,这也可能与文件系统有关检查这一讨论和他们的一些测试可以缩小问题范围:确保XML包含无害的html实体$str=str_replace(数组(“&”、“>”、”
<file>
    <loc>
        http://%2Fhome%2Fusers%2Fjdfvnftp%2Fjdfv.nl%2Fptp%2Ftorrents%2FBuck.2011.DVD.XviD.AVI.106682.torrent.importedfileName
    </loc>
    <lastmod>2012-05-29</lastmod>
</file>