作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试从数据库查询生成 xml。
这是生成的 xml 链接: http://mydeal.ge/api/xml
但是当我尝试解析这个 xml 时,我得到一个错误:http://wallsparade.com/test.php .
我的代码是:
public function xml()
{
$res = $this->db->query('custom query');
if($res->num_rows() > 0)
{$output = '<?xml version="1.0"?>'. "\n";
$output .= "<deals>";
foreach($res->result() as $item)
{
$output .= "<sale id = '".$item->id."'>";
$output .= "<link>".$item->link."</link>";
$output .= "<title>".urlencode($item->title)."</title>";
$output .= "<image>".$item->image."</image>";
$output .= "<text>".urlencode($item->text)."</text>";
$output .= "<time>".$item->time."</time>";
$output .= "<price>".$item->price."</price>";
$output .= "<parcent>".$item->parcent."</parcent>";
$output .= "</sale>";
}
$output .= '</deals>';
}
echo $output;
}
有什么问题?
最佳答案
看起来您正在开发 API。为什么不使用 CodeIgniter 的 RESTServer 插件?
这一切都为您处理,您不必担心格式问题。您可以选择以 JSON 或 XML 格式输出。
Phil 开发的插件:https://github.com/philsturgeon/codeigniter-restserver
关于php - 如何在codeigniter中生成xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17854296/
我是一名优秀的程序员,十分优秀!