List Info

Thread: UTF-8 and capitalize issues




UTF-8 and capitalize issues
user name
2006-03-09 17:22:45
Hi everyone,

I'm applying the capitalize modifier to a particular text
variable,  
which works as expected in most cases. What has recently
come up is  
that non-english characters are throwing a bit of a kink
into my  
plan. For example, Galápagos is coming out as GaláPagos with
the  
capitalize modifier.

I looked through the forums and didn't find any solutions
that  
worked, including using the setlocale() PHP function on my
page...  
All my Smarty template pages are set to charset=utf-8 in the
headers,  
and my mysql tables and text fields are utf8_general_ci.

So at this point I'm at a bit of a loss as to what I should
do next.

Any ideas?


Thanks!
Cameron

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

UTF-8 and capitalize issues
user name
2006-03-09 18:37:09
On Thu, Mar 09, 2006 at 09:22:45AM -0800, Cameron Perry
wrote:
> Hi everyone,
> 
> I'm applying the capitalize modifier to a particular
text variable,  
> which works as expected in most cases. What has
recently come up is  
> that non-english characters are throwing a bit of a
kink into my  
> plan. For example, Galápagos is coming out as GaláPagos
with the  
> capitalize modifier.
> 
> I looked through the forums and didn't find any
solutions that  
> worked, including using the setlocale() PHP function on
my page...  
> All my Smarty template pages are set to charset=utf-8
in the headers,  
> and my mysql tables and text fields are
utf8_general_ci.
> 
> So at this point I'm at a bit of a loss as to what I
should do next.
> 
> Any ideas?

write and use your own utf-8 aware modifier, like this one:

<?php

function smarty_modifier_mb_capitalize($string, $uc_digits =
false)
{
    return preg_replace_callback('!\b\w+\b!u',
'smarty_modifier_mb_capitalize_ucfirst', $string);
}

function smarty_modifier_mb_capitalize_ucfirst($string)
{
    return mb_strtoupper(mb_substr($string[0], 0, 1)) .
mb_substr($string[0], 1);
}

?>


 
> Thanks!
> Cameron
> 
> -- 
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub
.php
Re: UTF-8 and capitalize issues
user name
2007-03-06 05:48:28
On 28 Feb 2007, at 05:56, Brett wrote:

> Also, if I could ask, does anyone know if there will
still be a  
> problem with
> Unicode if one is searching for wildcard data between
ASCII text  
> within a
> preg_replace function? For example, will such a regular
expression  
> as this one
> choke, '({info)([^}]*?)(})s' , or will it only cause
problems  
> if one
> actually includes non-ASCII Unicode characters
explicitly within  
> the regexp?

Probably OK if you use the u pattern modifier as well.

Marcus
-- 
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessage
s.net/
marcussynchromedia.co.uk | http://www.synchromedi
a.co.uk/

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )