⑴ 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