PHP操作xml代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

/*获取图片新闻列表*/
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读取文件内容的几种方法详解

示例代码1: 用file_get_contents 以get方式获取内容复制代码 代码如下:<?php$url='http://www.baidu.com/';$html=file...

总结的一些PHP开发中的tips(必看篇)

一、开发习惯和php代码 1、准确的理解各种概念。现在的新东西层出不穷,望文生义和一知半解对开发工作有害无益;//比如我就碰到有人理解松散耦合(这个东西不新)的概念居然是要求代码不要有空...

php使用curl打开https网站的方法

本文实例讲述了php使用curl打开https网站的方法。分享给大家供大家参考。具体实现方法如下: $url = 'https://www.google.com.hk'; $ch...

PHP开发中的错误收集,不定期更新。

Fatal error: Non-static method Conn::__construct() cannot be called statically in /file.php 没...

php记录代码执行时间(实现代码)

复制代码 代码如下:$t1 = microtime(true);// ... 执行代码 ...$t2 = microtime(true);echo '耗时'.round($t2-$t1,...