Re: [SMARTY] UTF-8 and capitalize issues

"messju mohr" <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <20060309183709.GA20522@dune>
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
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEEHXVubKPpFA4n0URAn6RAJsERJ/LZTYiBdauCfW7dEVVcS9bywCdFgiW
Cw6Gn4a5Zms57xDsEpzsitU=
=Eo1S
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.