hugo-levet/strapi-php-rich-text-parser

A PHP parser for Strapi Rich Text fields

v1.3.3 2025-02-23 14:43 UTC

This package is auto-updated.

Last update: 2025-02-23 14:45:26 UTC


README

Latest Version Total Downloads Software License

A PHP parser for Strapi Rich Text fields

Usage

Get data from the Strapi API in StdClass format and pass it to the parser

use HugoLevet\StrapiPhpRichTextParser\RichTextParser;

$html_content = RichTextParser::jsonToHtml($content);

Using Shortcodes

You can add shortcodes like in WordPress by passing an array of shortcodes and their associated functions to the jsonToHtml function. For example:

$shortcodes = [
    'shortcode' => 'shortcodeFunction'
];

function shortcodeFunction($element)
{
    return 'Wubba Lubba Dub Dub';
}

$html = jsonToHtml($json, $shortcodes);
echo $html;

Environment variables

Make sure to set the environment variable STRAPI_URL with the URL of the Strapi API you are using

For development

To run the tests, use the following command:

./vendor/bin/phpunit tests