我能在xml文件中使用php循环吗?
我可以在xml文件中使用php循环来列出一系列递增的文件名,比如file 1.jpg file2.jpg file3.jpg等,这样我就不用手动键入了。我能在xml文件中使用php循环吗?,php,xml,Php,Xml,我可以在xml文件中使用php循环来列出一系列递增的文件名,比如file 1.jpg file2.jpg file3.jpg等,这样我就不用手动键入了。 如果是这样,我该怎么做?xml文件需要什么doctype等才能显示循环?您的问题有点模糊,我无法确定您是在读取xml文件还是在写入xml文件 假设您想要读取XML文件,并且假设您的XML看起来有点像这样: <?xml version="1.0" encoding="utf-8" ?> <rootnode> <i
如果是这样,我该怎么做?xml文件需要什么doctype等才能显示循环?您的问题有点模糊,我无法确定您是在读取xml文件还是在写入xml文件 假设您想要读取XML文件,并且假设您的XML看起来有点像这样:
<?xml version="1.0" encoding="utf-8" ?>
<rootnode>
<images>
<image>file_1.jpg</image>
<image>file_2.jpg</image>
<image>file_3.jpg</image>
</images>
</rootnode>
if (file_exists('test.xml')) {
$xml = simplexml_load_file('test.xml');
foreach($xml->images AS $image) {
echo $image;
}
} else {
exit('Failed to open test.xml.');
}
你的问题有点含糊不清,我不知道你是在读XML文件还是在写XML文件 假设您想要读取XML文件,并且假设您的XML看起来有点像这样:
<?xml version="1.0" encoding="utf-8" ?>
<rootnode>
<images>
<image>file_1.jpg</image>
<image>file_2.jpg</image>
<image>file_3.jpg</image>
</images>
</rootnode>
if (file_exists('test.xml')) {
$xml = simplexml_load_file('test.xml');
foreach($xml->images AS $image) {
echo $image;
}
} else {
exit('Failed to open test.xml.');
}
我要做的是指向一个输出XML的.php文件。您只需发送一个标题(“内容类型:text/xml”);并确保在输出的顶部添加 下面是一个例子:
<?php
header("Content-Type: text/xml");
print "<?xml version=\"1.0\"?>";
print "<rootNode>";
for(your loop stuff here) {
print "<node>" . $yourDataHere . "</node>";
}
print "</rootNode>";
?>
我要做的是指向一个输出XML的.php文件。您只需发送一个标题(“内容类型:text/xml”);并确保在输出的顶部添加 下面是一个例子:
<?php
header("Content-Type: text/xml");
print "<?xml version=\"1.0\"?>";
print "<rootNode>";
for(your loop stuff here) {
print "<node>" . $yourDataHere . "</node>";
}
print "</rootNode>";
?>
您想要的输出是什么?到目前为止你尝试了什么?你想要的结果是什么?到目前为止,您尝试了什么?只想知道是否有一种简单的方法可以使用php循环在xml文件(如file1.jpg file2.jpg file3.jpg)中生成文件名列表,而不是我必须从file1.jpg到file80.jpg,谢谢。我们只想知道是否有一种简单的方法可以在xml文件(如file1.jpg file2.jpg file3.jpg使用一个php循环,而不是我必须从file1.jpg列表到file80.jpg谢谢