You are here: Re: [PHP] Formating « PHP « IT news, forums, messages
Re: [PHP] Formating

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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация