Andrey
Andrey

Reputation: 83

alternative of mb_convert_encoding 'HTML-ENTITIES'

I use this code:

$wpCharset = "UTF8" //or any other charset
//http://php.net/manual/en/domdocument.loadhtml.php#74777
$content = mb_convert_encoding($content, 'HTML-ENTITIES', $wpCharset); 
$dom = new DOMDocument('1.0', $wpCharset);
$success = $dom->loadHtml('<!DOCTYPE html><html><meta http-equiv="Content-Type" content="text/html; charset=' . $wpCharset . '" /><body>' . $content);

The problem is that there are users who do not have a working "mbstring" extension installed on the server. Is there any alternative of mb_convert_encoding in this case?

Thanks a lot

Upvotes: 3

Views: 7894

Answers (1)

Alexis Peters
Alexis Peters

Reputation: 1621

just use $content = htmlentities($content)

It is UTF-8 Compatible. To see all Compatiblities check out php.net : https://www.php.net/manual/en/function.htmlentities.php

This just replaces double-quotes in the string which would be OK for XML. If you want to escape single-quotes to, use $content = htmlentitites($content,ENT_QUOTES)

Upvotes: 1

Related Questions