Is there a silver bullet function in PHP that will clean a string so it's suitable for RSS?
I have a lot of data that contains character开发者_如何学Cs that will normally break RSS. Is there a function or library in PHP that will handle these characters so they are suitable to be printed in an RSS Feed?
RSS is simply XML. So the characters escaped by htmlspecialchars() should be sufficient or htmlentities() escapes some extra characters, which might be useful.
http://php.net/manual/en/function.htmlentities.php
Take a look at the comments, there are some xmlentities
functions there you can use (since RSS is XML).
Use htmlentities() and it will encode the strange character in a strange encoding but it wouldn't break RSS.
htmlentities() isn't enough. When I tried it, it left many things that broke IE's and Firefox's feed readers. I am sure others would break too. When I used xml_entities() posted by somebody at http://php.net/manual/en/function.htmlentities.php, things that didn't work started to work.
精彩评论