hugo-levet / strapi-php-rich-text-parser
A PHP parser for Strapi Rich Text fields
Installs: 27
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 1
pkg:composer/hugo-levet/strapi-php-rich-text-parser
Requires (Dev)
- phpunit/phpunit: ^11.3
README
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