[nycphp-talk] Trim
Ben Ramsey
ben at atlphp.org
Tue Nov 23 10:22:51 EST 2004
Try this link and see if it helps you easily capture the phone number data:
http://benramsey.com/archive/cat/making_it_valid/making_it_valid_telephone_numbers.php
Then, after using the code at that link, just do:
$newphone = $area_code . '-' . $exchange . '-' . $number;
That should do it for you.
harvey wrote:
> Hi, I'm trying to 'normalize' phone numbers that are submitted via a
> form, so that they all appear as xxx-xxx-xxxx. I'm sure there's a more
> elegant way of doing it, but the following seems to work-- almost. But
> the trim part does not actually trim. I'm sure it has something to do
> with the type/case of the content submitted or the quotation marks or
> something like that. If I replace the GetSQL statement with ' (212)
> 555-1212 ', it works fine. I tried dropping the GetSQL and just using
> the $_Post, tried putting single and double quotes, etc. Any ideas? Thanks!
>
> $phone = GetSQLValueString($_POST['phone'],"text");
> $phone = trim($phone);
> $replace = array (") ","."," ");
> $newphone = str_replace($replace,"-",$phone);
> $newphone = str_replace("(","",$newphone);
>
>
> This is the GetSQLValueString function that Dreamweaver creates
> automatically:
>
> function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
> $theNotDefinedValue = "")
> { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) :
> $theValue;
> switch ($theType) {
> case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" :
> "NULL"; break;
> case "long":
> case "int": $theValue = ($theValue != "") ? intval($theValue) :
> "NULL"; break;
> case "double": $theValue = ($theValue != "") ? "'" .
> doubleval($theValue) . "'" : "NULL"; break;
> case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" :
> "NULL"; break;
> case "defined": $theValue = ($theValue != "") ? $theDefinedValue :
> $theNotDefinedValue; break; }
> return $theValue; }
--
Ben Ramsey
Atlanta PHP
http://atlphp.org
http://benramsey.com
More information about the talk
mailing list