PHP操作xml代碼
更新時(shí)間:2010年06月17日 09:32:33 作者:
下面的代碼是獲取圖片新聞列表的函數(shù)代碼,里面有操作xml文件的核心代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
/*獲取圖片新聞列表*/
function getPicNews($number=5){
require_once 'include/content_class.php';
$Content=new Content();
$sql='select contentid as id,title,pic,typeid from `cms_content` where pic<>"" order by input_time desc';
$rows=$Content->getRowsBySQL($sql,$number);
$dom=new DOMDocument('1.0','GBK');
$root=$dom->createElement('slider');
$dom->appendChild($root);
foreach($rows as $val){
$item=$dom->createElement('item');
$root->appendChild($item);
$title=$dom->createAttribute('title');
$title_text=$dom->createTextNode($val['title']);
$title->appendChild($title_text);
$item->appendChild($title);
$href=$dom->createAttribute('href');
$href_text=$dom->createTextNode('show.php?newsid='.$val['id'].'&classid='.$val['typeid']);
$href->appendChild($href_text);
$item->appendChild($href);
$imageurl=$dom->createAttribute('imageurl');
$imageurl_text=$dom->createTextNode($val['pic']);
$imageurl->appendChild($imageurl_text);
$item->appendChild($imageurl);
}
return $dom->saveXML();
}
您可能感興趣的文章:
- php之XML轉(zhuǎn)數(shù)組函數(shù)的詳解
- 基于PHP對(duì)XML的操作詳解
- php xml常用函數(shù)的集合(比較詳細(xì))
- PHP輸出XML到頁(yè)面的3種方法詳解
- 解析php DOMElement 操作xml 文檔的實(shí)現(xiàn)代碼
- php獲取本地圖片文件并生成xml文件輸出具體思路
- 自定義php類(查找/修改)xml文檔
- PHP讀取xml方法介紹
- 用PHP編寫和讀取XML的幾種方式
- PHP中3種生成XML文件方法的速度效率比較
- PHP中的生成XML文件的4種方法分享
- php輸出xml格式字符串(用的這個(gè))
- php xml 入門學(xué)習(xí)資料
- PHP操作XML作為數(shù)據(jù)庫(kù)的類
- PHP XML操作的各種方法解析(比較詳細(xì))
- php 修改、增加xml結(jié)點(diǎn)屬性的實(shí)現(xiàn)代碼
相關(guān)文章
php記錄代碼執(zhí)行時(shí)間(實(shí)現(xiàn)代碼)
本篇文章是對(duì)php記錄代碼執(zhí)行時(shí)間的實(shí)現(xiàn)代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以參考下2013-07-07
php將fileterms函數(shù)返回的結(jié)果變成可讀的形式
php將fileterms函數(shù)返回的結(jié)果變成可讀的形式,如: rwx--rx--x2011-04-04
PHP面向?qū)ο髮W(xué)習(xí)之parent::關(guān)鍵字
在PHP中不能定義重名的函數(shù),也包括不能再同一個(gè)類中定義重名的方法,所以也就沒(méi)有方法重載。下面這篇文章主要給大家介紹了PHP面向?qū)ο笾畃arent::關(guān)鍵字的相關(guān)資料,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-01-01
php針對(duì)cookie操作的隊(duì)列操作類實(shí)例
這篇文章主要介紹了php針對(duì)cookie操作的隊(duì)列操作類,以實(shí)例形式分析了設(shè)置cookie的常見方法,以及隊(duì)列操作cookie的方法,最后給出了針對(duì)常見問(wèn)題的總結(jié),需要的朋友可以參考下2014-12-12
Admin generator, filters and I18n
You need to modify your EntityFormFilter (where Entity is your object class - Article, Book, etc.).2011-10-10

