我维护一个以 HTML 格式保存富文本消息的公告板。现在我需要将所有这些消息迁移到需要 HTML 的 BBCode 表示的 Joomla Kunena 公告板。
是否有任何库可以将 HTML 干净地转换为 BBCode。有很多脚本可以将 BBCode 转换为 HTML,但反之则不然。
谢谢...
最佳答案
XSLT 在文本输出模式下应该是可行的:
<xsl:output method="text">
…
<xsl:template match="b|strong">[b]<xsl:apply-templates/>[/b]</xsl:template>
<xsl:template match="br"> </xsl:template>
<xsl:template match="p"> <xsl:apply-templates/> </xsl:template>
<xsl:template match="a">[url="<xls:value-of select="@href"/>"]<xsl:apply-templates/>[/url]</xsl:template>
<xsl:template match="text()"><x:value-of select="normalize-space(.)"/></xsl:template>
到达那里 parse HTML并使用 built-in XSLT processor .
关于php - 如何将 HTML 转换为 BBCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4308734/