Re: strtolower utf-8 char problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: strtolower utf-8 char problem

the_undefined
Hi,

UTF-8 supports Umlaute laut "äüö" and french notations like "ç".  I know that for sure.

I investigated on the problem, and in order to make sure we are on the same page, this is how my test setup looked like:
- The PHP document I used to test was UTF-8 encoded
- The html document that was served by the php document was treated as UTF-8 by the browser

Then I typed in <?php echo strtolower('ÜÜÜ'); ?> and got the same results as you. However something like this worked: <?php echo utf8_encode(strtolower(utf8_decode('ÜÜÜ'))); ?>. The best, and probably propper solution for the problem I came across was this: <?php echo mb_strtolower('ÜÜÜ', 'UTF-8') ?>.

I think this behavior makes total sense given that the normal php string functions can't deal with utf8 characters. Now the reason it worked with your non-php document was probably been that it has been treated as you OS native ISO entirely (php document, and web document).

When working with UTF-8 in CakePHP you should always pay attention to the following things:
1. All PHP documents you use Umlaute, or other utf8 characters in must be encoded UTF-8 themselves
2. The html document must be served as utf-8.
3. The database connection needs to be UTF-8.

For number #2 put this line on top of your layout view (i.e. default.thtml):
<?php header('Content-Type: text/html; charset=utf-8'); ?>

And this in your <head> section:
<?php echo $html->charset('UTF-8'); ?>

To ensure #3 is working, use this code in your AppModel:
class AppModel extends Model
{
    function __construct($id = null, $table = null, $ds = null)
    {
        parent::__construct($id, $table, $ds);
       
        if (!defined('MYSQL_SET_NAMES_UTF8') && $this->useTable!==false)
        {
            @$this->execute("SET NAMES 'UTF8'");
            define('MYSQL_SET_NAMES_UTF8', true);
        }
    }
}

Good luck and let me know how things are working out.

Best Regards,
Felix Geisendörfer


Ismael S. Kafeltz schrieb:
Try to set you codification on firefox/IE to ISO-8859-1

UTF-8 i guess don't suport this kind of chars äëïöüç

does this helps?
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
instead of UTF-8 ?

and/or
header('Content-Type:text/plain;charset=iso-8859-1');




  

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: strtolower utf-8 char problem

bt-4

Hello,

Thanks for your interest Felix.

As you said encoding and decoding the characters in UTF-8 does not
solve the problem. Also, charset and header issues don't solve it
alone. Furthermore, multibyte string methods works well for utf-8
encoding. Since my database is setted to UTF-8, it looks like working
well for now both inputs and outputs.

Regards,
bt

On Oct 30, 7:26 am, Felix Geisendörfer <[hidden email]> wrote:

>   Hi,
>
> UTF-8 supports Umlaute laut "äüö" and french notations like "ç".  I know
> that for sure.
>
> I investigated on the problem, and in order to make sure we are on the
> same page, this is how my test setup looked like:
> - The PHP document I used to test was UTF-8 encoded
> - The html document that was served by the php document was treated as
> UTF-8 by the browser
>
> Then I typed in <?php echo strtolower('ÜÜÜ'); ?> and got the same
> results as you. However something like this worked: <?php echo
> utf8_encode(strtolower(utf8_decode('ÜÜÜ'))); ?>. The best, and probably
> propper solution for the problem I came across was this: <?php echo
> mb_strtolower('ÜÜÜ', 'UTF-8') ?>.
>
> I think this behavior makes total sense given that the normal php string
> functions can't deal with utf8 characters. Now the reason it worked with
> your non-php document was probably been that it has been treated as you
> OS native ISO entirely (php document, and web document).
>
> When working with UTF-8 in CakePHP you should always pay attention to
> the following things:
> 1. All PHP documents you use Umlaute, or other utf8 characters in must
> be encoded UTF-8 themselves
> 2. The html document must be served as utf-8.
> 3. The database connection needs to be UTF-8.
>
> For number #2 put this line on top of your layout view (i.e. default.thtml):
> <?php header('Content-Type: text/html; charset=utf-8'); ?>
>
> And this in your <head> section:
> <?php echo $html->charset('UTF-8'); ?>
>
> To ensure #3 is working, use this code in your AppModel:
> class AppModel extends Model
> {
>     function __construct($id = null, $table = null, $ds = null)
>     {
>         parent::__construct($id, $table, $ds);
>
>         if (!defined('MYSQL_SET_NAMES_UTF8') && $this->useTable!==false)
>         {
>             @$this->execute("SET NAMES 'UTF8'");
>             define('MYSQL_SET_NAMES_UTF8', true);
>         }
>     }
>
> }Good luck and let me know how things are working out.
>
> Best Regards,
> Felix Geisendörfer
> --------------------------http://www.thinkingphp.orghttp://www.fg-webdesign.de
>
> Ismael S. Kafeltz schrieb:
>
> > Try to set you codification on firefox/IE to ISO-8859-1
>
> > UTF-8 i guess don't suport this kind of chars äëïöüç
>
> > does this helps?
> > <meta http-equiv="Content-Type" content="text/html;
> > charset=ISO-8859-1">
> > instead of UTF-8 ?
>
> > and/or
> > header('Content-Type:text/plain;charset=iso-8859-1');


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Loading...