我正在尝试动态创建 XML,但我遇到了一个障碍,由于某种原因,它会自动对 < 和 > 进行编码,我需要它来阻止它,因为它破坏了我的标签,但我在我的函数中看不到任何地方它告诉它进行编码。
function GenerateList($titleB, $descB, $thumbB, $dirB, $patternB){
if (is_dir($dirB)){
$myDirectory = opendir($dirB);
// get each entry
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}
// close directory
closedir($myDirectory);
// count elements in array
$indexCount = count($dirArray);
print ("<center><h1>'$titleB' Directory</h1>");
$true_count = 0;
// sort em
sort($dirArray);
$outputB = "<CATEGORY name=\"$titleB\" desc=\"$descB\" thumb=\"$thumbB\">";
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>");
print("<TR><TH>Filename</TH><th>Filesize</th><TH>Filename</TH><th>Filesize</th><TH>Filename</TH><th>Filesize</th></TR>");
print("<TR><TD colspan=2><TABLE border=0 cellpadding=0 cellspacing=0 class=whitelinks>");
// loop through the array of files and print them all
$one_third = round($indexCount/3);
$two_third = $one_third+$one_third;
for($index=0; $index < $indexCount; $index++) {
$ext = explode(".", $dirArray[$index]);
$parsed_title = preg_replace ($patternB, "", $ext[0]);
if ((substr("$dirArray[$index]", 0, 1) != ".")&&($ext[1] == "flv")){ // don't list hidden files
$true_count++;
print("<TR><TD><a href=\"$dirB$dirArray[$index]\">$parsed_title</a></td>");
print("<td>");
print(filesize($dirB.$dirArray[$index]));
print("</td>");
print("</TR>");
if ($one_third == ($index+1) || $two_third == ($index+1)){
print("</td></TR></table>");
print("</TD><TD colspan=2><TABLE border=0 cellpadding=0 cellspacing=0 class=whitelinks>");
}
$outputB .= "<ITEM>";
$outputB .= "<file_path>/$dirB".htmlentities($dirArray[$index])."</file_path>";
$outputB .= "<file_width>500</file_width>";
$outputB .= "<file_height>375</file_height>";
$outputB .= "<file_title>".$parsed_title."</file_title>";
$outputB .= "<file_desc>Loaded from a seperate txt file, index to match with the index of the dir file</file_desc>";
$outputB .= "<file_image>$thumbB</file_image>";
$outputB .= "<featured_image>$thumbB</featured_image>";
$outputB .= "<featured_or_not>true</featured_or_not>";
$outputB .= "</ITEM>";
}
}
print("</td></TR></table>");
print("</TR><td colspan=6 align=right>$true_count files</td></TABLE>");
};//if (file_exists($dirB))
$outputB .= "</CATEGORY>";
return $outputB;
};//function
然后我获取几个函数调用的最终输出并将其传递给 xml 解析器
//$output = 几个 GenerateList 函数的连接返回 $dom = new DOMDocument('1.0', 'utf-8');
$element = $dom->createElement('CONTENT',$output);
$dom->appendChild($element);
$xml_final = $dom->saveXML();
$dom->save("playlist.xml")