导航:首页 > 编程语言 > php写xml文件

php写xml文件

发布时间:2022-03-01 07:38:08

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

阅读全文

与php写xml文件相关的资料

热点内容
优信二手车解压后过户 浏览:63
Windows常用c编译器 浏览:780
关于改善国家网络安全的行政命令 浏览:835
安卓如何下载网易荒野pc服 浏览:656
javainetaddress 浏览:106
苹果4s固件下载完了怎么解压 浏览:1005
命令zpa 浏览:288
python编译器小程序 浏览:946
在app上看视频怎么光线调暗 浏览:542
可以中文解压的解压软件 浏览:595
安卓卸载组件应用怎么安装 浏览:915
使用面向对象编程的方式 浏览:342
程序员项目经理的年终总结范文 浏览:932
内衣的加密设计用来干嘛的 浏览:435
淮安数据加密 浏览:295
魔高一丈指标源码 浏览:984
松下php研究所 浏览:171
c回调java 浏览:403
梦幻端游长安地图互通源码 浏览:747
电脑本地文件如何上传服务器 浏览:315