gpt4 book ai didi

php - 如何在codeigniter中生成xml

转载 作者:可可西里 更新时间:2023-10-31 22:55:46 24 4
gpt4 key购买 nike

我正在尝试从数据库查询生成 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com