RE: [PHP-DEV] Would anybody find this useful besides me?

From: Date: Mon, 09 Apr 2001 21:04:36 +0000
Subject: RE: [PHP-DEV] Would anybody find this useful besides me?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-51239@lists.php.net to get a copy of this message
I've got a PHP coded version already, I was just looking at the interest in having this part of the language. My approach is more simplistic, I've never had a problem with it. function mprint($mask, $value, $mask_char = "X") { if (empty($value)) return false; $retval = ""; // init return value $vp = 0; // value position for ($i=0; $i<strlen($mask); $i++) { if ($mask[$i] == $mask_char) { // append char to retval $retval .= $value[$vp]; $vp++; // increment position } else { $retval .= $mask[$i]; // don't mess with this char } } if ($vp != strlen($value)) $retval .= substr($value,$vp,strlen($value)); // append left-overs return $retval; } /* end of function mprint() */ -Chris -----Original Message----- From: Joe Brown [mailto:joebrown@somewhere.com] Sent: Monday, 09 April, 2001 2-44 pM To: php-dev@lists.php.net Subject: Re: [PHP-DEV] Would anybody find this useful besides me? I wrote a little function to do something similar to that. It's a little weak but does a fairly good job formatting. Maybe sombody will make it better and send me the code too ;-) // format($element, $format) // element=<input ...> // format="(999)999-9999 xxxxx" // 9=numeric digit // X=converts alpha to uppercase // x=anything goes // anything-else=hardcoded format literals. // above format would take 1234567890 and conver it to (123)456-7890 // amazingly format="99/99/9999" doesn't add 0's but does convert 01012000 to // 01/01/2000 it also accepts 1/1/2000 and leaves it as 1/1/2000 // but "999-99-9999" truncates 333-2-24444 to 333-2-2444 // Use: // <form> // <input type=text name=f1 onchange="this.value=inputFormat(this.value,'99/99/9999')"> function format ($e,$f) { if (($e=='') || ($f=='')) return $e; $r=""; $numbers='0123456789'; $ei=0; $fi=0; while(strcmp($ev=substr($e,$ei,1),"") && strcmp($fv=substr($f,$fi,1),"")) { switch($fv) { case '9': if (strpos($numbers,$ev)!==false) { $r.=$ev; $ei++; $fi++; } else { // else clause causes 1/1/1999 to be accepted as such if (substr($f,$fi+1,1)==$ev) $fi++; else $ei++; } break; case 'X': $r.=strtoupper($ev); $ei++; $fi++; break; case 'x': $r.=$ev; $ei++; $fi++; break; default: if ($ev==$fv){ $r.=$fv; $ei++; $fi++; } else { $r.=$fv; $fi++; break; } } } return $r; } ""Chris Newbill"" <cnewbill@onewest.net> wrote in message news:JPEJKIFIJDECKPGFOLGFIELFCGAA.cnewbill@onewest.net... > Just curious to see if anybody else would see the usefulness of having a > masking print function? I dunno maybe call it mprint(). > > Where I could pass my mask, my value and optionally the mask char, > defaulting to something off I guess like "~". > > mprint ( mask , value [, mask_char]) > > So I could > > $str = mprint("(XXX) XXX.XXXX", "4064498056", "X"); > print $str; > > and would get > > (406) 449.8056 > > > Chris Newbill > OneWest.net Inc., > Programmer/Analyst > > 406.449.8056 > cnewbill@onewest.net > > /* > Windows crashed. > I am the Blue Screen of Death. > No one hears your screams. > */ > > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.dev (#51239) next »