VirtueMart Forum

VirtueMart Dev/Coding Central: VM1 (old version) => Virtuemart 1.1 Development (Archiv) => Quality & Testing VirtueMart 1.1.x => Topic started by: Replika on April 16, 2008, 07:53:54 AM

Title: Please do not use: utf8_encode(utf8_decode($text))
Post by: Replika on April 16, 2008, 07:53:54 AM
Since I can not access to dev.virtuemart.net, so I post here

My language charset is utf-8 and in the function safe_utf8_encode (which used in vmMail):
if( strtolower($charset) == 'utf-8') {
// safely decode and reencode the string
$text = utf8_encode(utf8_decode($text));
}

it damages the email subject.
example: "Sản phẩm được yêu cầu"
will be "S?n ph?m ???c yêu c?u"

Developers, please have a look.
Regards
--
Replika
Title: Re: Please do not use: utf8_encode(utf8_decode($text))
Post by: Soeren on April 23, 2008, 15:11:23 PM
Could you please try this modification of the safe_utf8_encode function ?

if( strtolower($charset) == 'utf-8' &&  !seems_utf8( $text )) {
// safely decode and reencode the string
$text = utf8_encode($text);
}


Does this work?
Title: Re: Please do not use: utf8_encode(utf8_decode($text))
Post by: korb on April 23, 2008, 17:18:26 PM
hi soeren
where goes this code? Does it solve the problem with PDF creation also?
Title: Re: Please do not use: utf8_encode(utf8_decode($text))
Post by: Replika on April 23, 2008, 20:33:09 PM
@Soeren
After checking, the code should be: ;)
if( strtolower($charset) == 'utf-8' && !vmAbstractLanguage::seems_utf8($text) ) {
// safely decode and reencode the string
$text = utf8_encode(utf8_decode($text));
}


edit:
I've had problem with utf8 in PDF also. Posted the feature request that using PDF creation in Joomla lib: http://dev.virtuemart.net/cb/issue/1584?navigation=true
Title: Re: Please do not use: utf8_encode(utf8_decode($text))
Post by: korb on April 25, 2008, 01:06:55 AM
hi replika,
this code provided actaly works? where do you place it?
Title: Re: Please do not use: utf8_encode(utf8_decode($text))
Post by: Replika on April 25, 2008, 07:05:37 AM
Quote from: korb on April 25, 2008, 01:06:55 AM
hi replika,
this code provided actaly works? where do you place it?
File: administrator/com_virtuemart/classes/language.class.php
Line: 150
But it's not for PDF issue
Title: Re: Please do not use: utf8_encode(utf8_decode($text))
Post by: greyow on April 25, 2008, 15:27:18 PM
Hi Soeren,

I think this encode is not needed.

For the most accentuated languages the ISO-8859-1 is not enough,
so the language file isn't possible to be written in ISO-8859-1.
The utf8_encode of php encodes an ISO-8859-1 string to UTF-8.

Interpreters know in what way to save the file, I think you should delete this part.

You can try it. (http://forum.virtuemart.net/index.php?topic=38247.0)