Skip to main content
Topic: EXPORT WITH ACCENTS AND OTHER SPECIAL CHARACTERS (Read 2260 times) previous topic - next topic

EXPORT WITH ACCENTS AND OTHER SPECIAL CHARACTERS

When I enter accented characters the export fails. Is ther a fix?


 

Re: EXPORT WITH ACCENTS AND OTHER SPECIAL CHARACTERS

Reply #2
@willvin Thanks for your quick response. I've followed the fix in the thread  https://phprad.com/forum/index.php?topic=743.0. Still the export problem.


Re: EXPORT WITH ACCENTS AND OTHER SPECIAL CHARACTERS

Reply #4
@willvin. I Know you can help me.  I Attach the files. The first record Id "11" has an accented "o" and is what produces the error in the export.

Re: EXPORT WITH ACCENTS AND OTHER SPECIAL CHARACTERS

Reply #5
@Ellen‍, please take the following steps. This issue will be fixed in the next phprad update.

add this code
Code: [Select]
<meta charset="UTF-8">
in the head tag before <title><?php echo $this->report_title; ?></title> and replace this
Code: [Select]
 body,
 h1,
 h2,
 h3,
 h4,
 h5,
 h6 {
 margin: 0px;
 padding: 0px;
[size=1] font-family: Arial, Helvetica, sans-serif;[/size]
 }
with this
Code: [Select]
 body,
 h1,
 h2,
 h3,
 h4,
 h5,
 h6 {
 margin: 0px;
 padding: 0px;
 font-family: "DejaVu Sans";
 }
in app/views/layouts/report_layout.php.

Now replace the following
Code: [Select]
 /**
 * DomDocument Manipulation
 * Set the inner html of a page element
 * @return string
 */
 private function setInnerHTML($element, $html)
 {
 $html = htmlentities($html);
 $fragment = $element->ownerDocument->createDocumentFragment();
 $fragment->appendXML($html);
 $clone = $element->cloneNode(); // Get element copy without children
 $clone->appendChild($fragment);
 $element->parentNode->replaceChild($clone, $element);
 }
with this
Code: [Select]
 /**
 * DomDocument Manipulation
 * Set the inner html of a page element
 * @return string
 */
 private function setInnerHTML($element, $html)
 {
 $html = html_entity_decode($html);
 $html = fixWrongUTF8Encoding($html);
 $fragment = $element->ownerDocument->createDocumentFragment();
 $fragment->appendXML($html);
 $clone = $element->cloneNode(); // Get element copy without children
 $clone->appendChild($fragment);
 $element->parentNode->replaceChild($clone, $element);
 }
in system/BaseView.php.

and finally, add this function
Code: [Select]
function fixWrongUTF8Encoding($String) { 
 $fix_accent_list = array(
 // 3 char errors first
 '‚' => '‚', '„' => '„', '…' => '…', '‡' => '‡',
 '‰' => '‰', '‹' => '‹', '‘' => '‘', '’' => '’',
 '“' => '“', '•' => '•', '–' => '–', '—' => '—',
 'â„¢' => '™', '›' => '›', '€' => '€',
 // 2 char errors
 'Â'  => 'Â', 'Æ’'  => 'ƒ', 'Ã'  => 'Ã', 'Ä'  => 'Ä',
 'Ã…'  => 'Å', 'â€'  => '†', 'Æ'  => 'Æ', 'Ç'  => 'Ç',
 'ˆ'  => 'ˆ', 'È'  => 'È', 'É'  => 'É', 'Ê'  => 'Ê',
 'Ë'  => 'Ë', 'Å’'  => 'Œ', 'ÃŒ'  => 'Ì', 'Ž'  => 'Ž',
 'ÃŽ'  => 'Î', 'Ñ'  => 'Ñ', 'Ã’'  => 'Ò', 'Ó'  => 'Ó',
 'â€'  => '”', 'Ô'  => 'Ô', 'Õ'  => 'Õ', 'Ö'  => 'Ö',
 '×'  => '×', 'Ëœ'  => '˜', 'Ø'  => 'Ø', 'Ù'  => 'Ù',
 'Å¡'  => 'š', 'Ú'  => 'Ú', 'Û'  => 'Û', 'Å“'  => 'œ',
 'Ãœ'  => 'Ü', 'ž'  => 'ž', 'Þ'  => 'Þ', 'Ÿ'  => 'Ÿ',
 'ß'  => 'ß', '¡'  => '¡', 'á'  => 'á', '¢'  => '¢',
 'â'  => 'â', '£'  => '£', 'ã'  => 'ã', '¤'  => '¤',
 'ä'  => 'ä', 'Â¥'  => '¥', 'Ã¥'  => 'å', '¦'  => '¦',
 'æ'  => 'æ', '§'  => '§', 'ç'  => 'ç', '¨'  => '¨',
 'è'  => 'è', '©'  => '©', 'é'  => 'é', 'ª'  => 'ª',
 'ê'  => 'ê', '«'  => '«', 'ë'  => 'ë', '¬'  => '¬',
 'ì'  => 'ì', '®'  => '®', 'î'  => 'î', '¯'  => '¯',
 'ï'  => 'ï', '°'  => '°', 'ð'  => 'ð', '±'  => '±',
 'ñ'  => 'ñ', '²'  => '²', 'ò'  => 'ò', '³'  => '³',
 'ó'  => 'ó', '´'  => '´', 'ô'  => 'ô', 'µ'  => 'µ',
 'õ'  => 'õ', '¶'  => '¶', 'ö'  => 'ö', '·'  => '·',
 '÷'  => '÷', '¸'  => '¸', 'ø'  => 'ø', '¹'  => '¹',
 'ù'  => 'ù', 'º'  => 'º', 'ú'  => 'ú', '»'  => '»',
 'û'  => 'û', '¼'  => '¼', 'ü'  => 'ü', '½'  => '½',
 'ý'  => 'ý', '¾'  => '¾', 'þ'  => 'þ', '¿'  => '¿',
 'ÿ'  => 'ÿ', 'À'  => 'À',
 // 1 char errors last
 'Ã' => 'Á', 'Å' => 'Š', 'Ã' => 'Í', 'Ã' => 'Ï',
 'Ã' => 'Ð', 'Ã' => 'Ý', 'Ã' => 'à', 'í' => 'í'
 );
 
 //Cyrillic/Russian characters
 $Cyrillic = [
 'а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п',
 'р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я',
 'А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П',
 'Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я'
 ];
 
 //Cyrillic/Russian characters in UTF-8
 $UTF8Equivalent = ['а','б','в','г','д','е','Ñ‘','ж','з','и','й','к','л','м','н','о','п','Ñ€','с','Ñ‚','у','Ñ„','Ñ…','ц','ч','ш','щ','ÑŠ','Ñ‹','ÑŒ','э','ÑŽ','я', 'А','Б','Ð’','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','Ðœ','Н','О','П', 'Ð ','С','Т','У','Ф','Ð¥','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я'
 ];

 //we get our accent characters and its utf-8 equivalent characters
 $error_chars = array_keys($fix_accent_list);
 $real_chars  = array_values($fix_accent_list);
 
 //we relpace the weird utf-8 accent characters with its appropriate characters
 $String = str_replace($UTF8Equivalent, $Cyrillic, $String);   

 //we replace the weird utf-8 cyrillic characters with its appropriate characters and return it.
 return str_replace($error_chars, $real_chars, $String);
}
to helpers/functions.php.

Now preview and enjoy ;) .



Re: EXPORT WITH ACCENTS AND OTHER SPECIAL CHARACTERS

Reply #6
@willvin. You really are a genius. Thank you very much for your attention and support. It works perfect.