⑴ php输出xml文件应该如何写
最简单的办法就是拼凑:
echo '<?xml version="1.0" encoding="utf-8" ?>';
echo '<skplyaer>';
ech ...
echo '</ckplayer'>;
⑵ php如何生成xml文件
<?php
#使用dom生成xml,注意生成的xml中会没有空格。
$dom=new DOMDocument('1.0','utf-8');
$path="test.xml"; // $path 为xml文件的存储路径。
$mole=$dom->createElement('newmole');// root node
$dom->appendChild($mole);
$year=$dom->createElement('year'); // add attribute node
$name=$dom->createAttribute('name');
$name->nodeValue="最新动态";
$year->setAttributeNode($name);
$mole->appendChild($year);
$news=$dom->createElement('news');
$year->appendChild($news);
$date=$dom->createElement('date');
$date_value=$dom->createTextNode('01-24');
$date->appendChild($date_value);
$news->appendChild($date);
$title=$dom->createElement('title');
$title_value=$dom->createTextNode('<![CDATA[最新动态]]>');
$title->appendChild($title_value);
$news->appendChild($title);
$info=$dom->createElement('info');
$info_value=$dom->createTextNode('<![CDATA[ 表面采用进口楸木木皮拼贴成精美的拼花,自然清晰的木材纹理得到完美的呈现,各种材质的合理搭配缔造了雅意系列精致的家具产品。
]]>');
$info->appendChild($info_value);
$news->appendChild($info);
echo $dom->saveXML();
$dom->save($path);
?>
⑶ PHP如何将数组写入XML请直接提供代码。感谢!!!
<?php
$imgdir = '你存放图片的文件夹';
$logfile = '你要写入的文件名';
$submit = $_POST['submit'];
if($submit == 'write'){
include('lib/write.class.php');
$wt = new writeTo();
$wt->while($imgdir,$logfile);
}
?>
<input type = 'submit' name = 'submit' value = 'write'>
这个是前提文件
下面的是类文件
<?php
class writeTo{
function isjpg($filename){
/*
用来判断是否是 .jpg结尾的文件 由于本机器无JPG 所以使用PHP
代替了JPG 你自己使用的时候请自行替换
*/
if(preg_match('/\.php$/',$filename)){
return true;
}
false;
}
function listjpg($dir){//查看文件夹内的所有JPG文件名并存入数组
$arr = array();
if(is_dir($dir)){
$dp=dir($dir);
while($file=$dp->read()){
if($this->isjpg($file)){
$arr[substr($file,0,(strlen($file)-4))] = $file;
}
}
}
$dp->close();
return $arr;
}
function write($dir,$filename){//利用前面生成的数字重写文件
if($link = fopen($filename,'w+')){
//由于使用W+所以如果存在该文件请给予读写权限 如不存在则程序自动建立
$str = "<?xml version='1.0' encoding='utf-8'?>\n";
$str .= " <path>\n";
$arr = $this->listjpg($dir);
foreach($arr as $key => $v){
$str .= " <url info=".$key.">pic/".$v."</url>\n";
}
$str .= " <\path>\n";
if(fwrite($link,$str)){
fclose($link);
return true;
}
return false;
}
return false;
}
}
⑷ php怎么生成xml文件
<?php
$dom = new DOMDocument('1.0','utf-8');
$path = "test.xml";
$swf = $dom->createElement("swf");
$dom->appendChild($swf);
$name = $dom->createAttribute('num');
$name->value = '3';
$swf->setAttributeNode($name);
$value = $dom->createElement("value");
$swf->appendChild($value);
$name2 = $dom->createAttribute('vi');
$name2->value = "images/1.jpg";
$value->setAttributeNode($name2);
$text = $dom->createTextNode('');
$value->appendChild($text);
echo $dom->saveXML();
$dom->save($path);
⑸ 如何将php页面表单数据写入xml文件中
php本身提供的——domxml
参见
http://expert.csdn.net/Expert/TopicView1.asp?id=1597294
⑹ PHP读写XML文件
直接用fwrite 写一个 xml的文件就行了,
注意包含xml文件头,然后每个节点都写全
⑺ php 怎么生成xml文件并且导出
<?xml version="1.0" encoding="utf-8"?>
<article>
<item>
<title size="1">title1</title>
<content>content1</content>
<pubdate>2009-10-11</pubdate>
</item>
<item>
<title size="1">title2</title>
<content>content2</content>
<pubdate>2009-11-11</pubdate>
</item>
</article>
⑻ php环境下如何生成xml文件
header("Content-type:text/xml");
设置好这个后,把xml看错是字符串,直接echo就可以。
为了比较准确处理,建议还是用xml读写对象处理比较不容易出错。最后依然是echo 输出字符串。
⑼ 请教如何在php里修改xml文件
if ( file_exists ( 'out.xml' )) {
$xml = simplexml_load_file ( 'out.xml' );
foreach ($xml->pic->list as $key => $value) {
$attr = (array) $value->attributes ();
var_mp($attr['@attributes']['smallinfo']);
}
} else {
exit( 'Failed to open test.xml.' );
} 这个只能取到里面的值 想改里面的值建议去下个simple_html_dom或者phpQuery