Whats the best way to pass html embed code via rss feed to a rss parser in php?

时光毁灭记忆、已成空白 提交于 2020-01-21 12:18:26

问题


Im trying to put an html embed code for a flash video into the rss feed, which will then be parser by a parser (magpie) on my other site. How should I encode the embed code on one side, and then decode it on the other so I can insert clean html into the DB on the receiving server?


回答1:


Since RSS is XML, you might want to check out CDATA, which I believe is valid in the various RSS specs.

<summary><![CDATA[Data Here]]>

Here's the w3schools entry on it: http://www.w3schools.com/XML/xml_cdata.asp




回答2:


htmlencode/htmldecode should do the trick.




回答3:


Ive been using htmlentities/html_entity_decode but for some reason it doesnt work with the parser. In a normal test it works, but parser always returns html code without < > " characters.




回答4:


RSS is XML. It has very specific rules for encoding HTML. If you're generating it, I'd recommend using an xml library to write the node containing HTML, to be sure you get the encoding right.

HTMLencode will only perform the escaping necessary for embedding data within HTML, XML rules are more strict.




回答5:


Instead of writing your own RSS XML feed, consider using the Django syndication framework from django.contrib.syndication:

https://docs.djangoproject.com/en/dev/ref/contrib/syndication/

It also supports enclosures, which is the RSS way for embedding images or video.

For custom tags, there is also an lowlevel API which allows you to change the XML: https://docs.djangoproject.com/en/dev/ref/contrib/syndication/#the-low-level-framework



来源:https://stackoverflow.com/questions/113024/whats-the-best-way-to-pass-html-embed-code-via-rss-feed-to-a-rss-parser-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!