0

I want to convert HTML to BBCode, I've already found this: How to convert HTML to BBCode

but this is with XSLT, and I haven't ever worked with XSLT

If there's any way to convert HTML to BBCode with PHP please let me know

Here's my decode function:

public function decode()
{
    $doc = new DOMDocument();
    $doc->loadHTML("<html><body></body></html>");

    $xsml = $doc->load("bbcode.xsl");

    $proc = new XSLTProcessor();
    $proc->importStylesheet($xsml);

    return $proc->transformToXml($xsml);
}

and here's the xsl

<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>

Thanks

0 Answers0