听dj战歌,就上傲气战歌网!2015年传奇家族玩家最喜爱的家族战歌网
战歌推荐:战歌网 战歌网dj Mc战歌网 DJ战歌网下载 激情战歌-冰雪战歌网 客服Q:350317
新闻搜索:

Handling XML data(5)

作者:傲气战歌网     来源:www.27zg.com    发表时间:2014-03-24 03:02

The reason why I chose to use the get_*() and set_*() methods inside the class even though the properties are accessible as well is because if one later wanted to change how to retrieve or set the data only those functions would have to be updated and not everything using them.

RSSFeed::add_item() adds items to the RSS feed. It checks that the data is okay and throws some exceptions if it isn't. It also converts a possible pubDate from a UNIX timestamp to a formatted date. It returns $this to enable the usage of chaining - something which we've used quite a lot in this tutorial actually.

The switch in RSSFeed::parse_item() is there to make the contents of "content" CDATA. Any parser worth using will not parse CDATA and therefore it is not neccessary to convert special characters to HTML entities.

Now we've generated an RSS feed without writing a single line of XML. It is guaranteed to be 100% well-formed and it's easy to add a new item to the feed. In a real application you would get the items from some sort of database and add them to the feed.

Conclusion

Hopefully you've learned a lot about XML and PHP during this tutorial. We've covered the following things:

  • SimpleXML
  • PHP DOM
  • If you have any suggestions feel free to comment here or PM me at the forums.

    战歌网

    数据统计中!!

    最新评论共有  位网友发表了评论
    发表评论(评论内容:请文明参与评论,禁止谩骂攻击!)
    不能超过250字节,请自觉遵守互联网相关政策法规.
    昵称:    发表评论 (Ctrl+Enter快速回复)

    关于本站 | 合作加盟 | 合作说明 | 免责声明 | 广告服务 | 网站地图

    健康游戏忠告:抵制不良游戏 拒绝盗版游戏 注意自我保护 谨防受骗上当 适度游戏益脑 沉迷游戏伤身 合理安排时间 享受健康生活

    如有意见和建议,请惠赐E-mail至350317@qq.com 联系QQ:350317

    Copyright © 2010-2013 Www.27zG.CoM
    苏ICP备11049833号