Skip to content

Commit

Permalink
fix ccp richtext modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
recursivetree committed Aug 13, 2023
1 parent 6c88cb8 commit b590cac
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ function clean_ccp_html($html, $acceptable_tags = '<font><br><i>')
if (empty($html))
return '';

// CCP's rich text might be encapsulated in u'<content>'. Remove the u'
$html = preg_match("/u'(.*)'/", $html, $match) ? $match[1] : $html;


// handle escaped UTF-8 data
// taken from https://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha
$html = preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UTF-16BE');
}, $html);

// Handle Unicode cases.
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');

Expand Down

0 comments on commit b590cac

Please sign in to comment.