|
Posted by Bruno B B Magalhγes on 07/07/05 19:31
Hi Richard,
On Jul 5, 2005, at 6:20 PM, Richard Lynch wrote:
> On Mon, July 4, 2005 6:48 pm, Bruno B B MagalhΓ£es said:
>> For example I have a brazilian zipcode witch is stored in database as
> Is she a Good Witch, or a Bad Witch? :-)
Ups, hehehehe!
>> 22252970 and must be formatted as NNNNN-NNN, where N is a number.
>> Also I have a tax id with is also stored as numeric value only, for
>> example 05117635472 and outputted as NNN.NNN.NNN-NN... Is that any
>> way that I can do it generic, storing the formatting strings ('NNNNN-
>> NNN') with languages strings, so it is localised and this would be
>> parsed as: string::format($string, $format);
>
> //Untested code:
> function format($string, $format){
> $slen = strlen($string);
> $flen = strlen($format);
> $result = '';
> for ($f = 0, $s = 0; $f <= $flen && $s <= $slen; $f++){
> $fc = $format[$f];
> $sc = $string[$s];
> switch($fc){
> case 'N':
> if (!strstr('0123456789', $sc)){
> //Suitable error for mal-formed data here.
> //$fc should be a digit, but it's not.
> }
> $result .= $sc;
> $s++;
> break;
> //Assume you need 'C'haracter data at some point in the future:
> case 'C':
> if (!stristr('abcdefghijklmnopqrstuvwxyz', $fc)){
> //more error-code (see above)
> }
> $result .= $sc;
> $s++;
> break;
> default:
> $result .= $fc;
> break;
> }
> }
> return $result;
> }
>
> I also don't think you want to tie it into "Locale" unless the data
> itself
> is tagged with Locale, rather than the viewer's Locale.
>
> A US zip code is NNNNN[-NNNN] no matter what language you are
> viewing it in.
I was thinking about that, but for example the dates and times
current are formatted language specific..
I was thinking about applying this internationalisation also to those
strings and number, but probably as you said that's not a good idea
after all.
But, either way, MANY thanks for your wonderful help.
Regards,
Bruno B B Magalhaes
Navigation:
[Reply to this message]
|