在php中,准备字符串并创建XML/RSS Feed [英] In php, Prepare string and create XML/RSS Feed

查看:93
本文介绍了在php中,准备字符串并创建XML/RSS Feed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建自己的RSS/XML feed.我从数据库中获取数据以进行显示,但仍然收到无效的字符错误.如果字符串中包含&"号或其他奇怪字符,则XML无效.

I want to create my own RSS/XML feed. I fetch data from the database to display, but keep getting invalid character errors. If the string has an ampersand or other strange characters in it, the XML will be invalid.

我尝试使用urlencode和htmlentities,但是这些不能捕获需要转义的所有可能字符.有谁知道一个PHP函数将为XML输出准备一个字符串?

I tried using urlencode and htmlentities, but these don't capture all possible characters which need to be escaped. Does anyone know of a PHP function which will prepare a string for XML output?

推荐答案

html特殊字符应该足够了.但是不要忘记将第三个参数(字符集)设置为与字符串字符集匹配的字符集.

htmlspecialchars should be enough. But don't forget to set the 3rd parameter (charset) to the character set matching the string charset.

这篇关于在php中,准备字符串并创建XML/RSS Feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆