[PHP] How to format a strign with a generic mask??
Hi Folks, First of all, sorry for my english, but it isn´t good. I ´ll try to be cleary. Weel, I need a simple function that takes a string and format with a generic mask. Like this example above: $string1 = "12345678" $string2 = "11062003" echo format_string ("#.###.###-#", $string1); // --> Returns 1.234.567-8 echo format_string ("##/##/", $string1); // --> Returns 11/06/2003 Does anybody here have an idea to how to do this? Thanks, and sorry again for my english. ______ Felipe Desiderati e Souza Analista de Sistemas e Suporte Unimed - Fed. Est. Rio de Janeiro ICQ#: 68557248 __
Re: [PHP] How to find if a string is an integer?
try this: if (ereg("^[0-9]+$", $_POST["var_int")) echo "is int"; []´s Felipe - Original Message - From: "Jean-Christian IMbeault" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, June 11, 2003 9:44 PM Subject: [PHP] How to find if a string is an integer? > I would like to test wether a $_POST var is an integer or not. What is > the best way? > > I ahve tried is_int() but that fails b/c $_POST vars are always strings. > is_numeric() doesn't help because it doesn't differentiate bewteen > numbers (1.0) and integers (1). > > The best I have been able to come up with is: > > if (is_numeric($var) && is_int((int)$var)) > > But I ma hoping there is something simpler ... > > Any ideas? > > thansk, > > Jean-Christian Imbeault > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to find if a string is an integer?
> Felipe Desiderati wrote: > > try this: > > > > if (ereg("^[0-9]+$", $_POST["var_int")) > > echo "is int"; > > That's not the best regexp. It doesn' take into account negative > integers and isn't there a [[:numeric:]] or something like regexp that > would work better. > > I'm looking for the simplest method and the one that takes the less > processing power :) > > Calling up the regular expression engine dounds pretty processing > intensive ... Sorry, I don´t know that you needed an effective snipet. And you are right, I only writed for positive integers. Try something like apply 2 type cast simunltaneous. if ( (string) ((int) $_POST["var_int"]) == $_POST["var_int"]) echo "is int"; And sorry for my english, []´s Felipe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How to format a strign with a generic mask??
Thanks, helps a lot!! []´s Felipe > "Felipe Desiderati" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >I need a simple function that takes a string and formats > > with a generic mask. Like this example above: > > > >$string1 = "12345678" > >$string2 = "11062003" > > > >echo format_string ("#.###.###-#", $string1); // --> Returns 1.234.567-8 > >echo format_string ("##/##/", $string1); // --> Returns 11/06/2003 > > > >Does anybody here have an idea to how to do this? > > > Here is a function that does what you want, with > a test stand. HTH! > > > > function format_string($mask, $contents, $ch = '#') { > > $c = 0; > $str = ""; > > for($m = 0; $m < strlen($mask); $m++) > if ($mask[$m] == $ch) { > $str .= $contents[$c]; > $c++; > } > else > $str .= $mask[$m]; > > return($str); > } > > ?> > > > > Mask: > Content: > Maskchar: > > > > > Result: $_GET['ch']); ?> > > > > -- > Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada > v3.1 GCS/E/AT d- s+: a- C+++ L++>+++$ P+ E- W+++$ N++ K? w++ M PS+ > PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+ > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] It´s a test!!
sorry, It´s only a test!!