How to convert HTML to bbcode

I support a bulletin board that saves text messages in HTML format. Now I need to transfer all these messages to the Joomla Kunena bulletin board, which requires a BBCode HTML representation.

Is there any library for converting HTML to BBCode. There are several scripts for BBCode for HTML, but not vice versa.

Thanks...

+6
html php bbcode
source share
2 answers

This should be feasible with XSLT in text output mode:

<xsl:output method="text"> … <xsl:template match="b|strong">[b]<xsl:apply-templates/>[/b]</xsl:template> <xsl:template match="br">&#10;</xsl:template> <xsl:template match="p">&#10;<xsl:apply-templates/>&#10;</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> 

To find analyze HTML and use the built-in XSLT processor .

+7
source share

I would recommend using regular expressions to convert <b> tags to [b] . This should not be so difficult, since all you need to do is get the HTML code and pass it to a PHP script that can save it in some file that you can save in your new forum.

Hope this helps, RayQuang

0
source share

All Articles