With the PHP SDK, I’m using a basic content type with a rich-text field for “bodyContent”. Like so:
$renderer = new \Contentful\RichText\Renderer();
$renderedHTML = $renderer->render($content->get(‘bodyContent’));
And then I output $renderedHTML to the page. However, I noticed that if a content author types in special characters like an ampersand, greater-than, less-than signs, or double quote marks…they don’t get encoded by the Renderer() class.
I can just run an htmlspecialchars() over the results either, because then it will escape the actual HTML elements like paragraph tags, heading tags, links, etc.
Is there a means to properly encode HTML content from rich-text?