PHP code example of webfoo / html-to-shopify-rich-text

1. Go to this page and download the library: Download webfoo/html-to-shopify-rich-text library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webfoo / html-to-shopify-rich-text example snippets


use Webfoo\HtmlToShopifyRichText\HtmlToShopifyRichText;

$html = '<h1>Hello World</h1><p>This is a <strong>test</strong> paragraph.</p>';
$richText = HtmlToShopifyRichText::convert($html);

// $richText will contain the JSON representation of the Shopify Rich Text

try {
    $richText = HtmlToShopifyRichText::convert($html);
} catch (InvalidHtmlException $e) {
    // Handle invalid HTML
} catch (ConversionException $e) {
    // Handle conversion errors
} catch (JsonEncodingException $e) {
    // Handle JSON encoding errors
}